rpcap: compare against the new authentication reply size - #1712
Conversation
The third test in the authentication reply length chain compared plen against sizeof(struct rpcap_authreply_old) again, which is always true at that point, leaving the following else unreachable. Compare against sizeof(struct rpcap_authreply) so that a reply longer than the old layout but shorter than the new one is diagnosed as intended.
|
Thank you, at the branching level this logic is clear. One thing that would need verifying before merging this is whether this change unmasks another dormant bug — remote capture code tends to have bugs. |
|
Thanks for looking at it. I don't think this can unmask anything downstream, because it doesn't turn a rejected reply into an accepted one — it only changes which error path a rejected reply takes. Going through the cases:
So before and after, a 3..7 byte reply ends the same way: errbuf set, payload discarded, -1 returned. No new code becomes reachable on a success path, and the error path that does become reachable mirrors the two that were already there — same discard, same return value. Happy to back this with a stub server replying with 0, 1, 2, 3, 5, 7, 8 and 12 bytes and show identical caller-visible behaviour before and after, if you'd like that on the record before merging. |
|
There are three possible valid reply sizes:
In db93927, in late January 2019, I added protocol version negotiation. That's case 2 above. In dc14a7b, in early August 2022, I added the byte order. That's case 3 above. The
The |
|
I'm currently horsewhipping Appveyor into getting past the failures to connect when trying to download tools, to which it's unfortunately prone (it appears to be going through a particularly bad time of that right now). |
rpcap_doauth() validates the payload length of an authentication reply against the two possible reply layouts:
The chain of tests is:
By the time the third test is reached, plen > sizeof(struct rpcap_authreply_old) is already known, so the test is always true and the final else is unreachable. Its comment describes the case it was meant to catch - a reply longer than the old layout but shorter than the new one, i.e. 3 to 7 bytes - which currently takes the "read the full new reply" branch instead.
Comparing against sizeof(struct rpcap_authreply) makes the last branch reachable and restores the intended check.
No security impact: rpcap_recv() already refuses to read more than the declared payload (if (toread > *plen)), so a 3..7 byte reply is rejected either way, currently with "Message payload is too short" rather than the more specific message. This is a correctness and diagnostics fix, which is why it is sent as an ordinary pull request rather than through the private security reporting process.