From: Guy Harris Date: Wed, 22 Oct 2014 19:31:21 +0000 (-0700) Subject: Do bounds checking when unescaping PPP. X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/1af0defd43415f15ccc26d14d8f79ff53c67d57c Do bounds checking when unescaping PPP. Clean up a const issue while we're at it. --- diff --git a/print-ppp.c b/print-ppp.c index ea8e00b2..c1eb4552 100644 --- a/print-ppp.c +++ b/print-ppp.c @@ -1266,11 +1266,15 @@ trunc: static void ppp_hdlc(const u_char *p, int length) { - u_char *b, *s, *t, c; + u_char *b, *t, c; + const u_char *s; int i, proto; const void *se; - b = (u_int8_t *)malloc(length); + if (length <= 0) + return; + + b = (u_char *)malloc(length); if (b == NULL) return; @@ -1279,14 +1283,13 @@ ppp_hdlc(const u_char *p, int length) * Do this so that we dont overwrite the original packet * contents. */ - for (s = (u_char *)p, t = b, i = length; i > 0; i--) { + for (s = p, t = b, i = length; i > 0 && TTEST(*s); i--) { c = *s++; if (c == 0x7d) { - if (i > 1) { - i--; - c = *s++ ^ 0x20; - } else - continue; + if (i <= 1 || !TTEST(*s)) + break; + i--; + c = *s++ ^ 0x20; } *t++ = c; }