]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Fix lcpconfopts[] bounds check.
authorGuy Harris <[email protected]>
Fri, 24 Nov 2017 20:22:07 +0000 (12:22 -0800)
committerGuy Harris <[email protected]>
Fri, 24 Nov 2017 20:22:22 +0000 (12:22 -0800)
The subscript is unsigned, so it's guaranteed to be >= 0.  It should
thus be checked against the size of the array, not against some other

print-ppp.c

index 3ab4c96dc4ffe2b620d6e1c32f5d152dbd14c1d8..d17420f5e21efc07e7b51ba9d2c3ce92ea881904 100644 (file)
@@ -179,9 +179,6 @@ static const struct tok cpcodes[] = {
 #define LCPOPT_SDLOS   29
 #define LCPOPT_PPPMUX  30
 
-#define LCPOPT_MIN LCPOPT_VEXT
-#define LCPOPT_MAX LCPOPT_PPPMUX
-
 static const char *lcpconfopts[] = {
        "Vend-Ext",             /* (0) */
        "MRU",                  /* (1) */
@@ -216,6 +213,8 @@ static const char *lcpconfopts[] = {
        "PPP-Muxing",           /* (30) */
 };
 
+#define NUM_LCPOPTS    (sizeof lcpconfopts / sizeof lcpconfopts[0])
+
 /* ECP - to be supported */
 
 /* CCP Config Options */
@@ -604,14 +603,14 @@ print_lcp_config_options(netdissect_options *ndo,
        if (length < len)
                return 0;
        if (len < 2) {
-               if ((opt >= LCPOPT_MIN) && (opt <= LCPOPT_MAX))
+               if (opt < NUM_LCPOPTS)
                        ND_PRINT((ndo, "\n\t  %s Option (0x%02x), length %u (length bogus, should be >= 2)",
                                  lcpconfopts[opt], opt, len));
                else
                        ND_PRINT((ndo, "\n\tunknown LCP option 0x%02x", opt));
                return 0;
        }
-       if ((opt >= LCPOPT_MIN) && (opt <= LCPOPT_MAX))
+       if (opt < NUM_LCPOPTS)
                ND_PRINT((ndo, "\n\t  %s Option (0x%02x), length %u", lcpconfopts[opt], opt, len));
        else {
                ND_PRINT((ndo, "\n\tunknown LCP option 0x%02x", opt));