diff options
author | 2017-10-11 10:14:15 +0000 | |
---|---|---|
committer | 2017-10-11 10:14:15 +0000 | |
commit | 194bc1319d0390a2049d35e5aabce87506cd25e3 (patch) | |
tree | 5966e2b7fa98cc04c5e5b7152f4806f3c89bb2d4 | |
parent | If $MODE.site fails, store random.seed and error out. Based on a diff (diff) | |
download | wireguard-openbsd-194bc1319d0390a2049d35e5aabce87506cd25e3.tar.xz wireguard-openbsd-194bc1319d0390a2049d35e5aabce87506cd25e3.zip |
Tweak parse_decimal() and its invocations to emit a
single error message ("expecting integer between x and y")
and to properly handle ';' in error cases.
-rw-r--r-- | sbin/dhclient/clparse.c | 26 | ||||
-rw-r--r-- | sbin/dhclient/parse.c | 26 |
2 files changed, 23 insertions, 29 deletions
diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c index 5eca5acb41e..cbd45591e5d 100644 --- a/sbin/dhclient/clparse.c +++ b/sbin/dhclient/clparse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clparse.c,v 1.131 2017/10/10 14:01:08 krw Exp $ */ +/* $OpenBSD: clparse.c,v 1.132 2017/10/11 10:14:15 krw Exp $ */ /* Parser for dhclient config and lease files. */ @@ -686,42 +686,26 @@ parse_option_decl(FILE *cfile, struct option_data *options) dp = (uint8_t *)&ip_addr; break; case 'l': /* Signed 32-bit integer. */ - if (parse_decimal(cfile, buf, 'l') == 0) { - parse_warn("expecting signed 32-bit " - "integer."); - skip_to_semi(cfile); + if (parse_decimal(cfile, buf, 'l') == 0) return -1; - } len = 4; dp = buf; break; case 'L': /* Unsigned 32-bit integer. */ - if (parse_decimal(cfile, buf, 'L') == 0) { - parse_warn("expecting unsigned 32-bit " - "integer."); - skip_to_semi(cfile); + if (parse_decimal(cfile, buf, 'L') == 0) return -1; - } len = 4; dp = buf; break; case 'S': /* Unsigned 16-bit integer. */ - if (parse_decimal(cfile, buf, 'S') == 0) { - parse_warn("expecting unsigned 16-bit " - "integer."); - skip_to_semi(cfile); + if (parse_decimal(cfile, buf, 'S') == 0) return -1; - } len = 2; dp = buf; break; case 'B': /* Unsigned 8-bit integer. */ - if (parse_decimal(cfile, buf, 'B') == 0) { - parse_warn("expecting unsigned 8-bit " - "integer."); - skip_to_semi(cfile); + if (parse_decimal(cfile, buf, 'B') == 0) return -1; - } len = 1; dp = buf; break; diff --git a/sbin/dhclient/parse.c b/sbin/dhclient/parse.c index a3b84682090..0c3f8f005e2 100644 --- a/sbin/dhclient/parse.c +++ b/sbin/dhclient/parse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.c,v 1.68 2017/10/10 14:01:08 krw Exp $ */ +/* $OpenBSD: parse.c,v 1.69 2017/10/11 10:14:15 krw Exp $ */ /* Common parser code for dhcpd and dhclient. */ @@ -291,8 +291,8 @@ int parse_decimal(FILE *cfile, unsigned char *buf, char fmt) { const char *errstr; - char *val; - int bytes, token; + char *val, *msg; + int bytes, rslt, token; long long numval, low, high; token = next_token(&val, cfile); @@ -323,13 +323,23 @@ parse_decimal(FILE *cfile, unsigned char *buf, char fmt) } numval = strtonum(val, low, high, &errstr); - if (errstr != NULL) - return 0; + if (errstr == NULL) { + numval = htobe64(numval); + memcpy(buf, (char *)&numval + (sizeof(numval) - bytes), bytes); + return 1; + } - numval = htobe64(numval); - memcpy(buf, (char *)&numval + (sizeof(numval) - bytes), bytes); + rslt = asprintf(&msg, "expecting integer between %lld and %lld", low, + high); + if (rslt != -1) { + parse_warn(msg); + free(msg); + } - return 1; + if (token != ';') + skip_to_semi(cfile); + + return 0; } int |