Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/time Bail out if the string does not look like a ti...



details:   https://anonhg.NetBSD.org/src/rev/ce905eda4b52
branches:  trunk
changeset: 345263:ce905eda4b52
user:      christos <christos%NetBSD.org@localhost>
date:      Sun May 15 20:36:42 2016 +0000

description:
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.

diffstat:

 lib/libc/time/strptime.c |  18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)

diffs (110 lines):

diff -r 16c4bfe4623c -r ce905eda4b52 lib/libc/time/strptime.c
--- a/lib/libc/time/strptime.c  Sun May 15 15:44:43 2016 +0000
+++ b/lib/libc/time/strptime.c  Sun May 15 20:36:42 2016 +0000
@@ -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 @@
 
        if (mandatory)
                *bp = rp;
+       if (!isalnum((unsigned char)*buf))
+               return 0;
        tz = tzalloc(buf);
        if (tz == NULL)
                return 0;
@@ -474,6 +476,7 @@
                         * 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 @@
                                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 @@
                                }
                                /* '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 @@
                                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 @@
                                        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 @@
                                /*
                                 * 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 @@
                                        continue;
                                }
 loadzone:
+printf("loadzone\n");
                                /*
                                 * The hard way, load the zone!
                                 */
@@ -612,6 +624,7 @@
                                }
                                break;
                        }
+printf("offs=%ld i=%d\n", (long)offs, i);
                        if (isdigit(*bp))
                                goto out;
                        switch (i) {
@@ -635,6 +648,7 @@
                        }
                        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 */



Home | Main Index | Thread Index | Old Index