]> asedeno.scripts.mit.edu Git - PuTTY.git/commit
Tighten up pointer handling after ssh_pkt_getstring.
authorSimon Tatham <anakin@pobox.com>
Mon, 29 Feb 2016 19:38:12 +0000 (19:38 +0000)
committerSimon Tatham <anakin@pobox.com>
Mon, 29 Feb 2016 19:59:37 +0000 (19:59 +0000)
commitb49a8db1b42d12a035b0d17d8c101b8556920112
treef3a2664764d10c48695eec40f8d088334a2abd47
parentbc6c15ab5f636e05b7e91883f0031a7e06117947
Tighten up pointer handling after ssh_pkt_getstring.

ssh_pkt_getstring can return (NULL,0) if the input packet is too short
to contain a valid string.

In quite a few places we were passing the returned pointer,length pair
to a printf function with "%.*s" type format, which seems in practice
to have not been dereferencing the pointer but the C standard doesn't
actually guarantee that. In one place we were doing the same job by
hand with memcpy, and apparently that _can_ dereference the pointer in
practice (so a server could have caused a NULL-dereference crash by
sending an appropriately malformed "x11" type channel open request).
And also I spotted a logging call in the "forwarded-tcpip" channel
open handler which had forgotten the field width completely, so it was
erroneously relying on the string happening to be NUL-terminated in
the received packet.

I've tightened all of this up in general by normalising (NULL,0) to
("",0) before calling printf("%.*s"), and replacing the two even more
broken cases with the corrected version of that same idiom.
misc.h
ssh.c