hfiref0x / LightFTP

Small x86-32/x64 FTP Server
BSD 2-Clause "Simplified" License
232 stars 83 forks source link

Back to back PASV requests cause connection failure #2

Closed ve3jrw closed 6 years ago

ve3jrw commented 7 years ago

This is a bit challenging to replicate, I had to use an old version of wget to generate a test that replicates the problem. Using wget 1.8.2 launch simultaneous retrievals. Might be easier to reproduce by writing a text script with two connections open.

If the PASV requests ends up back to back, the first succeeds, but the on the second one LightFTP fails with:

451 Requested action aborted. Local error in processing.\r\n

Attached is the Wireshark capture illustrating the problem

failedpasv.zip

ve3jrw commented 7 years ago

Neglected to mention this is running the Windows version of the code.

ve3jrw commented 7 years ago

Root cause of the problem is that the PASV port number is generated using GetTickCount64().

Should two requests occur within the same tick, they will use the same port # and the second bind will fail as a result of the address being already in use. The logic needs retry logic generating the port number to find an alternate unused port.

hfiref0x commented 7 years ago

Hello,

Thank you for feedback. I believe the root of the problem is same for both of your reported issues. I didn't updated Windows version for long time and there were some changes, so I would like to ask you test it again with newest version I just uploaded. Thanks again.

ve3jrw commented 7 years ago

They are not the same problems as the missing port number issue is seen on single as well as combined requests. It always happens. Where as this problem only happens when there are close requests.

I addressed the missing reported port number problem by combining the string parts together in one step instead of the current method which does it in pieces.

Not sure at this point when I'll have a chance to test as it will be a bit before I'm back on that project and the fix I've put in is addressing the issue. Will follow up as soon as I'm able.