summaryrefslogtreecommitdiffstats
path: root/sbin/dhclient/parse.c
diff options
context:
space:
mode:
authorkrw <krw@openbsd.org>2017-10-09 21:33:11 +0000
committerkrw <krw@openbsd.org>2017-10-09 21:33:11 +0000
commitb26721ec52e57b77c83ccee9e2a2462a3affa6cf (patch)
treed361529cc00341c9f585ca4ef2c070d91c03cbe1 /sbin/dhclient/parse.c
parentclarify the order in which config statements are used. (diff)
downloadwireguard-openbsd-b26721ec52e57b77c83ccee9e2a2462a3affa6cf.tar.xz
wireguard-openbsd-b26721ec52e57b77c83ccee9e2a2462a3affa6cf.zip
Tweak parse_lease_time() to emit a single message on
failure ("expecting unsigned 32-bit decimal value") and to properly handle the terminating ';' in error situations. Make parse_lease_time() return an int to indicate success or failure as its friends do. Also avoid swapping endianess twice. Use == 1 vs != 0 when checking parse_ip_addr() return value.
Diffstat (limited to 'sbin/dhclient/parse.c')
-rw-r--r--sbin/dhclient/parse.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/sbin/dhclient/parse.c b/sbin/dhclient/parse.c
index afbdc690efe..2d3be889911 100644
--- a/sbin/dhclient/parse.c
+++ b/sbin/dhclient/parse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.c,v 1.65 2017/10/09 18:02:43 krw Exp $ */
+/* $OpenBSD: parse.c,v 1.66 2017/10/09 21:33:11 krw Exp $ */
/* Common parser code for dhcpd and dhclient. */
@@ -233,20 +233,26 @@ parse_ip_addr(FILE *cfile, struct in_addr *addr)
/*
* lease-time :== NUMBER SEMI
*/
-void
+int
parse_lease_time(FILE *cfile, time_t *timep)
{
- uint32_t value;
+ const char *errstr;
+ char *val;
+ long long numval;
+ int token;
- if (parse_decimal(cfile, (char *)&value, 'L') == 0) {
- parse_warn("expecting unsigned 32-bit decimal value.");
- skip_to_semi(cfile);
- return;
+ token = next_token(&val, cfile);
+ numval = strtonum(val, 0, UINT32_MAX, &errstr);
+ if (errstr == NULL) {
+ *timep = numval;
+ return 1;
}
- *timep = betoh32(value);
+ parse_warn("expecting unsigned 32-bit decimal value.");
+ if (token != ';')
+ skip_to_semi(cfile);
- parse_semi(cfile);
+ return 0;
}
int