With an input of `-28` the expression `(-ctl->cpacketsize - MINPACKET)` became 0, which triggered a zero division. This error is fixed by introducing a check to see if there is any room for randomness. Furthermore, a check of the input arguments in the command line and in curses is performed.
buf[i++] = c; /* need more checking on 'c' */
}
buf[i] = '\0';
- ctl->cpacketsize = atoi(buf);
+ int new_packetsize = atoi(buf);
+ if (abs(ctl->cpacketsize) >= MINPACKET && abs(ctl->cpacketsize) < MAXPACKET) {
+ ctl->cpacketsize = new_packetsize;
+ }
return ActionNone;
case 'b':
mvprintw(2, 0, "Ping Bit Pattern: %d\n", ctl->bitpattern);
case 's':
ctl->cpacketsize =
strtoint_or_err(optarg, "invalid argument");
+ if (abs(ctl->cpacketsize) < MINPACKET || abs(ctl->cpacketsize) > MAXPACKET) {
+ error(EXIT_FAILURE, 0, "value of of range (%d - %d)", MINPACKET, MAXPACKET);
+ }
break;
case 'I':
ctl->InterfaceName = optarg;
smaller (reasonable packet sizes), and our rand() range much
larger, this effect is insignificant. Oh! That other formula
didn't work. */
- packetsize =
- MINPACKET + rand() % (-ctl->cpacketsize - MINPACKET);
+ if (-ctl->cpacketsize <= MINPACKET) {
+ /* There is no room to introduce randomness. */
+ packetsize = MINPACKET;
+ } else {
+ packetsize =
+ MINPACKET + rand() % (-ctl->cpacketsize - MINPACKET);
+ }
} else {
packetsize = ctl->cpacketsize;
}