Module Name:    src
Committed By:   christos
Date:           Sun May 15 20:36:42 UTC 2016

Modified Files:
        src/lib/libc/time: strptime.c

Log Message:
Bail out if the string does not look like a timezone (is empty or does not
start with a letter or a number). tzparse("") or tzparse(".45") don't fail.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/lib/libc/time/strptime.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/time/strptime.c
diff -u src/lib/libc/time/strptime.c:1.58 src/lib/libc/time/strptime.c:1.59
--- src/lib/libc/time/strptime.c:1.58	Fri Oct 30 23:42:00 2015
+++ src/lib/libc/time/strptime.c	Sun May 15 16:36:42 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: strptime.c,v 1.58 2015/10/31 03:42:00 ginsbach Exp $	*/
+/*	$NetBSD: strptime.c,v 1.59 2016/05/15 20:36:42 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 2005, 2008 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: strptime.c,v 1.58 2015/10/31 03:42:00 ginsbach Exp $");
+__RCSID("$NetBSD: strptime.c,v 1.59 2016/05/15 20:36:42 christos Exp $");
 #endif
 
 #include "namespace.h"
@@ -128,6 +128,8 @@ fromzone(const unsigned char **bp, struc
 
 	if (mandatory)
 		*bp = rp;
+	if (!isalnum((unsigned char)*buf))
+		return 0;
 	tz = tzalloc(buf);
 	if (tz == NULL)
 		return 0;
@@ -474,6 +476,7 @@ literal:
 			 * Note: J maybe used to denote non-nautical
 			 *       local time
 			 */
+printf("start parsing %s\n", bp);
 			if (mandatory)
 				while (isspace(*bp))
 					bp++;
@@ -515,6 +518,7 @@ namedzone:
 				if (delim(bp[1]) &&
 				    ((*bp >= 'A' && *bp <= 'I') ||
 				    (*bp >= 'L' && *bp <= 'Y'))) {
+printf("military\n");
 #ifdef TM_GMTOFF
 					/* Argh! No 'J'! */
 					if (*bp >= 'A' && *bp <= 'I')
@@ -534,6 +538,7 @@ namedzone:
 				}
 				/* 'J' is local time */
 				if (delim(bp[1]) && *bp == 'J') {
+printf("localtime\n");
 #ifdef TM_GMTOFF
 					tm->TM_GMTOFF = -timezone;
 #endif
@@ -551,8 +556,10 @@ namedzone:
 				if (delim(bp[0]) || delim(bp[1]) ||
 				    delim(bp[2]) || !delim(bp[3]))
 					goto loadzone;
+printf("findstring\n");
 				ep = find_string(bp, &i, nast, NULL, 4);
 				if (ep != NULL) {
+printf("foundstring\n");
 #ifdef TM_GMTOFF
 					tm->TM_GMTOFF = (-5 - i) * SECSPERHOUR;
 #endif
@@ -562,8 +569,10 @@ namedzone:
 					bp = ep;
 					continue;
 				}
+printf("findstring2\n");
 				ep = find_string(bp, &i, nadt, NULL, 4);
 				if (ep != NULL) {
+printf("foundstring2\n");
 					tm->tm_isdst = 1;
 #ifdef TM_GMTOFF
 					tm->TM_GMTOFF = (-4 - i) * SECSPERHOUR;
@@ -577,10 +586,12 @@ namedzone:
 				/*
 				 * Our current timezone
 				 */
+printf("findstring3\n");
 				ep = find_string(bp, &i,
 					       	 (const char * const *)tzname,
 					       	  NULL, 2);
 				if (ep != NULL) {
+printf("foundstring3\n");
 					tm->tm_isdst = i;
 #ifdef TM_GMTOFF
 					tm->TM_GMTOFF = -timezone;
@@ -592,6 +603,7 @@ namedzone:
 					continue;
 				}
 loadzone:
+printf("loadzone\n");
 				/*
 				 * The hard way, load the zone!
 				 */
@@ -612,6 +624,7 @@ loadzone:
 				}
 				break;
 			}
+printf("offs=%ld i=%d\n", (long)offs, i);
 			if (isdigit(*bp))
 				goto out;
 			switch (i) {
@@ -635,6 +648,7 @@ loadzone:
 			}
 			if (offs >= (HOURSPERDAY * SECSPERHOUR))
 				goto out;
+printf("done neg=%d offs=%ld\n", neg, (long)offs);
 			if (neg)
 				offs = -offs;
 			tm->tm_isdst = 0;	/* XXX */

Reply via email to