SOCKS4 Proxy Crash

Both sides - FTP Client and FTP Server
server - FTP server
client - FTP Client (SmartFTP)
Proxy - SOCKS4 Proxy Server
https://www.smartftp.com/Products/SmartF ... 4.protocol


You probably want to check what happens when you abort
the directory listing, with QUIT. The CMD socket is closed,
but the "DATA" socket remains open a while longer until
the connect times out due to server closed port to connect
to. Then the proxy replies with REJECT.

This has happened multiple times.
This *may* also be the result of lack of memory.
But I have no chance of checking this.

Test Case:
SOCKS4 Proxy (BIND not implemented yet, returns REJECT if requested)
Remote FTP Server: ftp.microsoft.com
Action: Press the Disconnect button when you see PASV
running up the screen, note that the directory listing
must not be completely downloaded before you press
the Disconnect button, it must be in-transit or what you
would like to call it.

This happens on the server client thread:
recv 8 Bytes (SOCKS4 header)
loop:
recv 1 Byte
if Buffer == NULL (all bits zeroed as described.)
break.
do proxy ..

If one of the two connections closes, they both close.

Reproducing this without a SOCKS4 Proxy server, will have these
results in the log:
[22:31:29] PASV
[22:31:29] 227 Entering Passive Mode (207,46,133,140,96,92).
[22:31:29] Opening data connection IP: 207,46,133,140,96,92 PORT: 24668.
[22:31:30] QUIT
[22:31:30] 221 Thank-you for using Microsoft products!
[22:31:30] Connection closed.
[22:31:30] An operation was attempted on something that is not a socket.

Also forgive me if im leaving something out, I was up all night
coding the SOCKS4 server, because I saw it was relatively easy
to achieve. And using 3 hours to figure out how to reverse IP->Host.
Well, the point is really that things arent always like it seems.
(Relatively speaking...)

I quickly read the protocol through, went to bed. Waited 20 min.
Thought: It doesnt seem too hard, why not...
Coded 80% of the server, went to bed, wake up.
Started coding again. All just because of a stupid (1st) hit on google.
Dont you just love google :)


Developers:
If you would like further info, binaries or dumps. Feel free to contact me.

You will now hear the sound of me falling on the keyboard after pressing preview + submit.

Thank you for the bug report.

Unfortunately I don't have time right now to look into this problem.

The FTP library implemented in SmartFTP 2.0 comes with a complete new library which shouldn't suffer the same problem.

But I will certainly debug it on a rainy sunday :-)