summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2017-10-11 15:06:28 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2017-10-11 15:06:28 +0000
commit04ce6cf65cd440ae21c1b48a7485d0d1deda058a (patch)
tree72e5ab8a269e0a0867f81d4620ba014efdb69ff6
parente5891c43b3436d72e143003baf85c04ff0173c2f (diff)
Tweak parse_date() again, this time to factor
code in the same way as the other parse_*() functions. Whitespace fix in comment while passing. Also conform to idiom that original data is not changed in the error path.
-rw-r--r--sbin/dhclient/clparse.c15
-rw-r--r--sbin/dhclient/dhcpd.h4
-rw-r--r--sbin/dhclient/parse.c31
3 files changed, 30 insertions, 20 deletions
diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c
index cbd45591e5d..b2ceca5e9a0 100644
--- a/sbin/dhclient/clparse.c
+++ b/sbin/dhclient/clparse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clparse.c,v 1.132 2017/10/11 10:14:15 krw Exp $ */
+/* $OpenBSD: clparse.c,v 1.133 2017/10/11 15:06:27 krw Exp $ */
/* Parser for dhclient config and lease files. */
@@ -549,6 +549,7 @@ parse_client_lease_declaration(FILE *cfile, struct client_lease *lease,
char *name)
{
char *val;
+ time_t date;
unsigned int len;
int token;
@@ -597,13 +598,19 @@ parse_client_lease_declaration(FILE *cfile, struct client_lease *lease,
free(val);
break;
case TOK_RENEW:
- lease->renewal = parse_date(cfile);
+ if (parse_date(cfile, &date) == 0)
+ return;
+ lease->renewal = date;
return;
case TOK_REBIND:
- lease->rebind = parse_date(cfile);
+ if (parse_date(cfile, &date) == 0)
+ return;
+ lease->rebind = date;
return;
case TOK_EXPIRE:
- lease->expiry = parse_date(cfile);
+ if (parse_date(cfile, &date) == 0)
+ return;
+ lease->expiry = date;
return;
case TOK_OPTION:
parse_option_decl(cfile, lease->options);
diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h
index e7321af8ae1..b6dfc022ac2 100644
--- a/sbin/dhclient/dhcpd.h
+++ b/sbin/dhclient/dhcpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcpd.h,v 1.229 2017/10/09 21:33:11 krw Exp $ */
+/* $OpenBSD: dhcpd.h,v 1.230 2017/10/11 15:06:27 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -186,7 +186,7 @@ int parse_lease_time(FILE *, time_t *);
int parse_decimal(FILE *, unsigned char *, char);
int parse_hex(FILE *, unsigned char *);
int parse_boolean(FILE *, unsigned char *);
-time_t parse_date(FILE *);
+int parse_date(FILE *, time_t *);
void parse_warn(char *);
/* bpf.c */
diff --git a/sbin/dhclient/parse.c b/sbin/dhclient/parse.c
index 0c3f8f005e2..c428d7bd749 100644
--- a/sbin/dhclient/parse.c
+++ b/sbin/dhclient/parse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.c,v 1.69 2017/10/11 10:14:15 krw Exp $ */
+/* $OpenBSD: parse.c,v 1.70 2017/10/11 15:06:27 krw Exp $ */
/* Common parser code for dhcpd and dhclient. */
@@ -373,10 +373,10 @@ parse_hex(FILE *cfile, unsigned char *buf)
*
* XXX Will break after year 9999!
*/
-time_t
-parse_date(FILE *cfile)
+int
+parse_date(FILE *cfile, time_t *date)
{
- char timestr[23]; /* "wyyyy/mm/dd hh:mm:ssUTC" */
+ char timestr[23]; /* "wyyyy/mm/ddhh:mm:ssUTC" */
struct tm tm;
char *val, *p;
size_t n;
@@ -385,7 +385,6 @@ parse_date(FILE *cfile)
memset(timestr, 0, sizeof(timestr));
- guess = -1;
n = 0;
do {
token = next_token(&val, cfile);
@@ -395,10 +394,16 @@ parse_date(FILE *cfile)
n = sizeof(timestr);
break;
case';':
- memset(&tm, 0, sizeof(tm)); /* 'cuz strptime ignores tm_isdt. */
+ /* strptime() ignores tm_isdt so ensure it is 0. */
+ memset(&tm, 0, sizeof(tm));
p = strptime(timestr, DB_TIMEFMT, &tm);
- if (p != NULL && *p == '\0')
+ if (p != NULL && *p == '\0') {
guess = timegm(&tm);
+ if (guess != -1) {
+ *date = guess;
+ return 1;
+ }
+ }
break;
default:
n = strlcat(timestr, val, sizeof(timestr));
@@ -407,14 +412,12 @@ parse_date(FILE *cfile)
}
} while (n < sizeof(timestr) && token != ';');
- if (guess == -1) {
- guess = 0;
- parse_warn("expecting UTC time.");
- if (token != ';')
- skip_to_semi(cfile);
- }
+ parse_warn("expecting UTC time.");
- return guess;
+ if (token != ';')
+ skip_to_semi(cfile);
+
+ return 0;
}
void