|
|
a86494 |
From 32027e199368dad9508965aae8cd8de5b6ab5231 Mon Sep 17 00:00:00 2001
|
|
|
a86494 |
From: Guy Harris <guy@alum.mit.edu>
|
|
|
a86494 |
Date: Sat, 18 Apr 2020 14:04:59 -0700
|
|
|
a86494 |
Subject: [PATCH] PPP: When un-escaping, don't allocate a too-large buffer.
|
|
|
a86494 |
|
|
|
a86494 |
The buffer should be big enough to hold the captured data, but it
|
|
|
a86494 |
doesn't need to be big enough to hold the entire on-the-network packet,
|
|
|
a86494 |
if we haven't captured all of it.
|
|
|
a86494 |
|
|
|
a86494 |
(backported from commit e4add0b010ed6f2180dcb05a13026242ed935334)
|
|
|
a86494 |
---
|
|
|
a86494 |
print-ppp.c | 18 ++++++++++++++----
|
|
|
a86494 |
1 file changed, 14 insertions(+), 4 deletions(-)
|
|
|
a86494 |
|
|
|
a86494 |
diff --git a/print-ppp.c b/print-ppp.c
|
|
|
a86494 |
index 891761728..33fb03412 100644
|
|
|
a86494 |
--- a/print-ppp.c
|
|
|
a86494 |
+++ b/print-ppp.c
|
|
|
a86494 |
@@ -1367,19 +1367,29 @@ print_bacp_config_options(netdissect_options *ndo,
|
|
|
a86494 |
return 0;
|
|
|
a86494 |
}
|
|
|
a86494 |
|
|
|
a86494 |
+/*
|
|
|
a86494 |
+ * Un-escape RFC 1662 PPP in HDLC-like framing, with octet escapes.
|
|
|
a86494 |
+ * The length argument is the on-the-wire length, not the captured
|
|
|
a86494 |
+ * length; we can only un-escape the captured part.
|
|
|
a86494 |
+ */
|
|
|
a86494 |
static void
|
|
|
a86494 |
ppp_hdlc(netdissect_options *ndo,
|
|
|
a86494 |
const u_char *p, int length)
|
|
|
a86494 |
{
|
|
|
a86494 |
+ u_int caplen = ndo->ndo_snapend - p;
|
|
|
a86494 |
u_char *b, *t, c;
|
|
|
a86494 |
const u_char *s;
|
|
|
a86494 |
- int i, proto;
|
|
|
a86494 |
+ u_int i;
|
|
|
a86494 |
+ int proto;
|
|
|
a86494 |
const void *se;
|
|
|
a86494 |
|
|
|
a86494 |
+ if (caplen == 0)
|
|
|
a86494 |
+ return;
|
|
|
a86494 |
+
|
|
|
a86494 |
if (length <= 0)
|
|
|
a86494 |
return;
|
|
|
a86494 |
|
|
|
a86494 |
- b = (u_char *)malloc(length);
|
|
|
a86494 |
+ b = (u_char *)malloc(caplen);
|
|
|
a86494 |
if (b == NULL)
|
|
|
a86494 |
return;
|
|
|
a86494 |
|
|
|
a86494 |
@@ -1388,10 +1398,10 @@ ppp_hdlc(netdissect_options *ndo,
|
|
|
a86494 |
* Do this so that we dont overwrite the original packet
|
|
|
a86494 |
* contents.
|
|
|
a86494 |
*/
|
|
|
a86494 |
- for (s = p, t = b, i = length; i > 0 && ND_TTEST(*s); i--) {
|
|
|
a86494 |
+ for (s = p, t = b, i = caplen; i != 0; i--) {
|
|
|
a86494 |
c = *s++;
|
|
|
a86494 |
if (c == 0x7d) {
|
|
|
a86494 |
- if (i <= 1 || !ND_TTEST(*s))
|
|
|
a86494 |
+ if (i <= 1)
|
|
|
a86494 |
break;
|
|
|
a86494 |
i--;
|
|
|
a86494 |
c = *s++ ^ 0x20;
|