Differences From Artifact [01175426be]:
- File sftp.c — part of check-in [1129bffc22] at 2013-07-11 12:24:53 on branch trunk — xfer_{up,down}load_gotpkt free their input sftp_packet as a side effect of handling it, but they do not free it if it isn't a packet they recognise as part of their upload/download. Invent a return value that specifically signals this, and consistently free pktin at every call site if that return value comes back. Also, ensure that that return value also always comes with something meaningful in fxp_error. (user: simon size: 34961)
To Artifact [6eaba51d1f]:
- File sftp.c — part of check-in [845f59bde8] at 2013-07-14 05:45:54 on branch trunk — 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. (user: simon size: 34968)
| ︙ | ︙ | |||
146 147 148 149 150 151 152 |
}
static int sftp_pkt_getstring(struct sftp_packet *pkt,
char **p, int *length)
{
*p = NULL;
if (pkt->length - pkt->savedpos < 4)
return 0;
| | | 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
}
static int sftp_pkt_getstring(struct sftp_packet *pkt,
char **p, int *length)
{
*p = NULL;
if (pkt->length - pkt->savedpos < 4)
return 0;
*length = toint(GET_32BIT(pkt->data + pkt->savedpos));
pkt->savedpos += 4;
if ((int)(pkt->length - pkt->savedpos) < *length || *length < 0) {
*length = 0;
return 0;
}
*p = pkt->data + pkt->savedpos;
pkt->savedpos += *length;
|
| ︙ | ︙ |