mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-15 18:17:32 -05:00
Tighten up a lot of casts from unsigned to int which are read by one
of the GET_32BIT macros and then used as length fields. Missing bounds checks against zero have been added, and also I've introduced a helper function toint() which casts from unsigned to int in such a way as to avoid C undefined behaviour, since I'm not sure I trust compilers any more to do the obviously sensible thing. [originally from svn r9918]
This commit is contained in:
2
sftp.c
2
sftp.c
@ -150,7 +150,7 @@ static int sftp_pkt_getstring(struct sftp_packet *pkt,
|
||||
*p = NULL;
|
||||
if (pkt->length - pkt->savedpos < 4)
|
||||
return 0;
|
||||
*length = GET_32BIT(pkt->data + pkt->savedpos);
|
||||
*length = toint(GET_32BIT(pkt->data + pkt->savedpos));
|
||||
pkt->savedpos += 4;
|
||||
if ((int)(pkt->length - pkt->savedpos) < *length || *length < 0) {
|
||||
*length = 0;
|
||||
|
Reference in New Issue
Block a user