]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-ppp.c
ppp: use the buffer stack for the de-escaping buffer.
[tcpdump] / print-ppp.c
index 2cf06c3634885f8104e4630889e1d76065ded425..9aed23eb9a64985afec065aa35caf971fa721141 100644 (file)
@@ -37,6 +37,8 @@
 
 #include "netdissect-stdinc.h"
 
+#include <stdlib.h>
+
 #include "netdissect.h"
 #include "extract.h"
 #include "addrtoname.h"
@@ -1358,7 +1360,6 @@ ppp_hdlc(netdissect_options *ndo,
        u_char *b, *t, c;
        const u_char *s;
        u_int i, proto;
-       const void *sb, *se;
 
        if (caplen == 0)
                return;
@@ -1366,9 +1367,11 @@ ppp_hdlc(netdissect_options *ndo,
         if (length == 0)
                 return;
 
-       b = (u_char *)nd_malloc(ndo, caplen);
-       if (b == NULL)
-               return;
+       b = (u_char *)malloc(caplen);
+       if (b == NULL) {
+               (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
+                       "%s: malloc", __func__);
+       }
 
        /*
         * Unescape all the data into a temporary, private, buffer.
@@ -1389,13 +1392,15 @@ ppp_hdlc(netdissect_options *ndo,
        }
 
        /*
-        * Change the end pointer, so bounds checks work.
-        * Change the pointer to packet data to help debugging.
+        * Switch to the output buffer for dissection, and save it
+        * on the buffer stack so it can be freed; our caller must
+        * pop it when done.
         */
-       sb = ndo->ndo_packetp;
-       se = ndo->ndo_snapend;
-       ndo->ndo_packetp = b;
-       ndo->ndo_snapend = t;
+       if (!nd_push_buffer(ndo, b, b, (u_int)(t - b))) {
+               free(b);
+               (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
+                       "%s: can't push buffer on buffer stack", __func__);
+       }
        length = ND_BYTES_AVAILABLE_AFTER(b);
 
         /* now lets guess about the payload codepoint format */
@@ -1437,13 +1442,11 @@ ppp_hdlc(netdissect_options *ndo,
         }
 
 cleanup:
-       ndo->ndo_packetp = sb;
-       ndo->ndo_snapend = se;
+       nd_pop_packet_info(ndo);
         return;
 
 trunc:
-       ndo->ndo_packetp = sb;
-       ndo->ndo_snapend = se;
+       nd_pop_packet_info(ndo);
        nd_print_trunc(ndo);
 }