Repository navigation
server: do not dispatch packets that failed to unmarshal - #694
Conversation
When makePacket fails with anything other than an unknown extended request, Serve closes the connection and then uses a bare break, which only leaves the switch. The partially decoded packet is still queued and executed by a worker with its missing fields left at their zero values, so a truncated SSH_FXP_MKDIR still creates the directory and a rename/symlink/link whose second path is cut off runs against "" (the working directory when one is configured). Break out of the receive loop instead, as RequestServer already does, so the malformed packet is dropped and Serve returns the decode error.
|
Should we entirely disconnect in such a situation, which is potentially recoverable, or should we reply to the client with a |
|
I'd keep the disconnect, at least for this PR. Replying isn't quite free either: the half-decoded packet doesn't always carry a usable ID ( That said, if you'd rather keep the session alive I'm happy to switch both servers to answering |
Repro: send an SSH_FXP_MKDIR to
Serverwith the trailing attrs field cut off (path intact). The server logs the decode error and closes the connection, but the directory is still created.Cause: on a
makePacketerror,Servecallssvr.conn.Close()and then a barebreak, which only leaves theswitch. The partially decoded packet is still queued and run by a worker with its missing fields set to zero values. A rename/symlink/hardlink/posix-rename with the second path missing runs against"", whichtoLocalPathturns into the working directory whenWithServerWorkingDirectoryis set.Fix: break out of the receive loop, as
RequestServer.serveLoopalready does, so the malformed packet is dropped andServereturns the decode error.TestServerDoesNotExecuteMalformedPacketfails without the change.