Skip to content

Commit 7115717

Browse files
committed
DHCP: Fix printing boolean options
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 the data and an error message if the length is not 1.
1 parent a691f1a commit 7115717

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

print-bootp.c

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -734,27 +734,32 @@ rfc1048_print(netdissect_options *ndo,
734734

735735
case 'B':
736736
/* boolean */
737-
while (len != 0) {
738-
uint8_t bool_value;
739-
if (!first)
740-
ND_PRINT(",");
741-
bool_value = GET_U_1(bp);
742-
switch (bool_value) {
743-
case 0:
744-
ND_PRINT("N");
745-
break;
746-
case 1:
747-
ND_PRINT("Y");
748-
break;
749-
default:
750-
ND_PRINT("%u?", bool_value);
751-
break;
752-
}
753-
++bp;
754-
--len;
755-
first = 0;
737+
{
738+
/* this option should be 1 byte long */
739+
if (len != 1) {
740+
ND_PRINT("[ERROR: length != 1 byte]");
741+
bp += len;
742+
len = 0;
743+
break;
744+
}
745+
746+
uint8_t bool_value;
747+
bool_value = GET_U_1(bp);
748+
switch (bool_value) {
749+
case 0:
750+
ND_PRINT("N");
751+
break;
752+
case 1:
753+
ND_PRINT("Y");
754+
break;
755+
default:
756+
ND_PRINT("%u?", bool_value);
757+
break;
756758
}
759+
++bp;
760+
--len;
757761
break;
762+
}
758763

759764
case 'b':
760765
case 'x':

0 commit comments

Comments
 (0)