]> The Tcpdump Group git mirrors - tcpdump/commitdiff
DHCP: Fix printing boolean options
authorFrancois-Xavier Le Bail <[email protected]>
Thu, 20 Mar 2025 13:10:13 +0000 (14:10 +0100)
committerFrancois-Xavier Le Bail <[email protected]>
Thu, 20 Mar 2025 13:13:09 +0000 (14:13 +0100)
For 'B', the options 19, 20, 27, 29, 30, 31, 34, 36, 39 and 116 that
use it are only 1 octet "0/1" boolean. No need for a while loop.

Print an error message if the length is not 1.

(backported from commit 711571721fd3f13f1082e4e803c4066e1a51c540)

print-bootp.c

index 747a9836a423d0e45fcf2922e587a897832db417..a541d74e8164c987ed924467cdeeff7f4d43a6e6 100644 (file)
@@ -730,27 +730,32 @@ rfc1048_print(netdissect_options *ndo,
 
                case 'B':
                        /* boolean */
-                       while (len > 0) {
-                               uint8_t bool_value;
-                               if (!first)
-                                       ND_PRINT(",");
-                               bool_value = GET_U_1(bp);
-                               switch (bool_value) {
-                               case 0:
-                                       ND_PRINT("N");
-                                       break;
-                               case 1:
-                                       ND_PRINT("Y");
-                                       break;
-                               default:
-                                       ND_PRINT("%u?", bool_value);
-                                       break;
-                               }
-                               ++bp;
-                               --len;
-                               first = 0;
+                   {
+                       /* this option should be 1 byte long */
+                       if (len != 1) {
+                               ND_PRINT("[ERROR: length != 1 byte]");
+                               bp += len;
+                               len = 0;
+                               break;
+                       }
+
+                       uint8_t bool_value;
+                       bool_value = GET_U_1(bp);
+                       switch (bool_value) {
+                       case 0:
+                               ND_PRINT("N");
+                               break;
+                       case 1:
+                               ND_PRINT("Y");
+                               break;
+                       default:
+                               ND_PRINT("%u?", bool_value);
+                               break;
                        }
+                       ++bp;
+                       --len;
                        break;
+                   }
 
                case 'b':
                case 'x':