summaryrefslogtreecommitdiff
path: root/sbin/dhclient
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2017-10-08 17:35:57 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2017-10-08 17:35:57 +0000
commit26c179ec63318aa3e41a254ad65c16e5bae5d731 (patch)
tree88ef6073f15dd19c98f98e5d6d20189bb6301eff /sbin/dhclient
parent6e095c35485e204ce09dae8a7b74765d5d76a91f (diff)
Simply parse_date() by trusting strptime() more and omitting
pointlessly precise error messages in favour of 'expecting UTC time'.
Diffstat (limited to 'sbin/dhclient')
-rw-r--r--sbin/dhclient/parse.c54
1 files changed, 22 insertions, 32 deletions
diff --git a/sbin/dhclient/parse.c b/sbin/dhclient/parse.c
index 02c51cf02a3..40fff614554 100644
--- a/sbin/dhclient/parse.c
+++ b/sbin/dhclient/parse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.c,v 1.63 2017/09/17 22:14:53 krw Exp $ */
+/* $OpenBSD: parse.c,v 1.64 2017/10/08 17:35:56 krw Exp $ */
/* Common parser code for dhcpd and dhclient. */
@@ -342,11 +342,13 @@ parse_hex(FILE *cfile, unsigned char *buf)
* Dates are always in UTC; first number is day of week; next is
* year/month/day; next is hours:minutes:seconds on a 24-hour
* clock.
+ *
+ * XXX Will break after year 9999!
*/
time_t
parse_date(FILE *cfile)
{
- char timestr[26]; /* "w yyyy/mm/dd hh:mm:ss UTC" */
+ char timestr[23]; /* "wyyyy/mm/dd hh:mm:ssUTC" */
struct tm tm;
char *val, *p;
size_t n;
@@ -355,45 +357,33 @@ parse_date(FILE *cfile)
memset(timestr, 0, sizeof(timestr));
+ guess = -1;
+ n = 0;
do {
- token = peek_token(NULL, cfile);
+ token = next_token(&val, cfile);
+
switch (token) {
- case TOK_NAME:
- case TOK_NUMBER:
- case TOK_NUMBER_OR_NAME:
- case '/':
- case ':':
- token = next_token(&val, cfile);
- n = strlcat(timestr, val, sizeof(timestr));
- if (n >= sizeof(timestr)) {
- /* XXX Will break after year 9999! */
- parse_warn("time string too long");
- skip_to_semi(cfile);
- return 0;
- }
+ case EOF:
+ n = sizeof(timestr);
break;
case';':
+ memset(&tm, 0, sizeof(tm)); /* 'cuz strptime ignores tm_isdt. */
+ p = strptime(timestr, DB_TIMEFMT, &tm);
+ if (p != NULL && *p == '\0')
+ guess = timegm(&tm);
break;
default:
- parse_warn("invalid time string");
- skip_to_semi(cfile);
- return 0;
- }
- } while (token != ';');
-
- parse_semi(cfile);
+ n = strlcat(timestr, val, sizeof(timestr));
+ break;
- memset(&tm, 0, sizeof(tm)); /* 'cuz strptime ignores tm_isdt. */
- p = strptime(timestr, DB_TIMEFMT, &tm);
- if (p == NULL || *p != '\0') {
- parse_warn("unparseable time string");
- return 0;
- }
+ }
+ } while (n < sizeof(timestr) && token != ';');
- guess = timegm(&tm);
if (guess == -1) {
- parse_warn("time could not be represented");
- return 0;
+ guess = 0;
+ parse_warn("expecting UTC time.");
+ if (token != ';')
+ skip_to_semi(cfile);
}
return guess;