Skip to content
Permalink
Browse files Browse the repository at this point in the history
PPP: When un-escaping, don't allocate a too-large buffer.
The buffer should be big enough to hold the captured data, but it
doesn't need to be big enough to hold the entire on-the-network packet,
if we haven't captured all of it.

(backported from commit e4add0b)
  • Loading branch information
guyharris authored and fxlb committed Apr 20, 2020
1 parent d95da9e commit 32027e1
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions print-ppp.c
Expand Up @@ -1367,19 +1367,29 @@ print_bacp_config_options(netdissect_options *ndo,
return 0;
}

/*
* Un-escape RFC 1662 PPP in HDLC-like framing, with octet escapes.
* The length argument is the on-the-wire length, not the captured
* length; we can only un-escape the captured part.
*/
static void
ppp_hdlc(netdissect_options *ndo,
const u_char *p, int length)
{
u_int caplen = ndo->ndo_snapend - p;
u_char *b, *t, c;
const u_char *s;
int i, proto;
u_int i;
int proto;
const void *se;

if (caplen == 0)
return;

if (length <= 0)
return;

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

Expand All @@ -1388,10 +1398,10 @@ ppp_hdlc(netdissect_options *ndo,
* Do this so that we dont overwrite the original packet
* contents.
*/
for (s = p, t = b, i = length; i > 0 && ND_TTEST(*s); i--) {
for (s = p, t = b, i = caplen; i != 0; i--) {
c = *s++;
if (c == 0x7d) {
if (i <= 1 || !ND_TTEST(*s))
if (i <= 1)
break;
i--;
c = *s++ ^ 0x20;
Expand Down

0 comments on commit 32027e1

Please sign in to comment.