Skip to content

Commit c6acf2d

Browse files
committed
fix integer overflow in dummynet
Found during fuzzing using AFL++: "strtoul()" returns a large positive number or a negative number. Next, the sanitizer detects an integer overflow in line 555 ("bw*= 1000") or in line 558 ("bw*= 1000000") or in line 563 ("bw*= 8"), and the program crashes with the error "SIGILL: illegal instruction operand".
1 parent 9138043 commit c6acf2d

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

ipfw/dummynet.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -552,15 +552,18 @@ read_bandwidth(char *arg, int *bandwidth, char *if_name, int namelen)
552552
bw = strtoul(arg, &end, 0);
553553
if (*end == 'K' || *end == 'k') {
554554
end++;
555-
bw *= 1000;
555+
if (__builtin_mul_overflow (bw, 1000, &bw))
556+
errx(EX_DATAERR, "bandwidth too large");
556557
} else if (*end == 'M' || *end == 'm') {
557558
end++;
558-
bw *= 1000000;
559+
if (__builtin_mul_overflow (bw, 1000000, &bw))
560+
errx(EX_DATAERR, "bandwidth too large");
559561
}
560562
if ((*end == 'B' &&
561563
_substrcmp2(end, "Bi", "Bit/s") != 0) ||
562564
_substrcmp2(end, "by", "bytes") == 0)
563-
bw *= 8;
565+
if (__builtin_mul_overflow (bw, 8, &bw))
566+
errx(EX_DATAERR, "bandwidth too large");
564567

565568
if (bw < 0)
566569
errx(EX_DATAERR, "bandwidth too large");

0 commit comments

Comments
 (0)