diff --git a/src/dhcp-common.c b/src/dhcp-common.c index 59dcbcd..58d173d 100644 --- a/src/dhcp-common.c +++ b/src/dhcp-common.c @@ -892,24 +892,23 @@ char *option_string(int prot, unsigned int opt, unsigned char *val, int opt_len, unsigned char *p; i = 0, j = 0; - while (1) + while (i + 2 <= opt_len) { p = &val[i]; GETSHORT(len, p); + if (i + 2 + len > opt_len) + break; /* malformed: body extends beyond option */ for (k = 0; k < len && j < buf_len; k++) { char c = *p++; if (isprint((unsigned char)c)) buf[j++] = c; } - i += len +2; - if (i >= opt_len) - break; - - if (j < buf_len) + i += len + 2; + if (i < opt_len && j < buf_len) buf[j++] = ','; } - } + } #endif else if ((ot[o].size & (OT_DEC | OT_TIME)) && opt_len != 0) {