Skip to content
Permalink
Browse files Browse the repository at this point in the history
Do bounds checking when unescaping PPP.
Clean up a const issue while we're at it.
  • Loading branch information
guyharris committed Oct 22, 2014
1 parent 15d235c commit 0f95d44
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions print-ppp.c
Expand Up @@ -1351,14 +1351,15 @@ static void
ppp_hdlc(netdissect_options *ndo,
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;

if (length <= 0)
return;

b = (uint8_t *)malloc(length);
b = (u_char *)malloc(length);
if (b == NULL)
return;

Expand All @@ -1367,14 +1368,13 @@ ppp_hdlc(netdissect_options *ndo,
* 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 && ND_TTEST(*s); i--) {
c = *s++;
if (c == 0x7d) {
if (i > 1) {
i--;
c = *s++ ^ 0x20;
} else
continue;
if (i <= 1 || !ND_TTEST(*s))
break;
i--;
c = *s++ ^ 0x20;
}
*t++ = c;
}
Expand Down

0 comments on commit 0f95d44

Please sign in to comment.