From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11162 Path: news.gmane.org!.POSTED!not-for-mail From: Julien Ramseier Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] strptime fixes Date: Sat, 18 Mar 2017 17:10:28 +0100 Message-ID: <25C67107-1C11-4606-9171-051707D92278@gmail.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_D5123C47-ED3D-4140-89AA-173197A2E41C" X-Trace: blaine.gmane.org 1489853474 20784 195.159.176.226 (18 Mar 2017 16:11:14 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 18 Mar 2017 16:11:14 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-11177-gllmg-musl=m.gmane.org@lists.openwall.com Sat Mar 18 17:11:10 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1cpGwe-0004jv-NM for gllmg-musl@m.gmane.org; Sat, 18 Mar 2017 17:11:08 +0100 Original-Received: (qmail 32336 invoked by uid 550); 18 Mar 2017 16:11:13 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 32121 invoked from network); 18 Mar 2017 16:10:42 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:message-id:date:to:mime-version; bh=NPfarDAD/cXVHdT8i9NUQCQb9TSUxoJY716AgVwU5A0=; b=er5jQw115Ls69tdDfw8AiYJvBnzoT27IxjpJPOuLQND8Kiyy1LDsqbbM2vVFmAOLNo JQTUm4HeSuIYKoK1VmXrpJ9EnKBJOKlFJ/rkF1HTDAmZWqZ37MfHXR2MNqQSYb3lO391 MhjcQWiGwipnpkH1jYzuvW1C7BNMoWzFMBODUt9hUfNHYwIJux+z5gC9+zuOg167L7Q5 Ne2hQhkAoho9RaJAdI+mJ8YA/uZO98Q/Ue4QysGpyrnw7kVCe7f/6D6S7n7PwEnRI7Oy pBt1YDaCrvD2dF2YirlqUPQbBTekuUjs5rAol4S+stvQhU73LmvHsHabPsfmKf6a/Xlr iqIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:message-id:date:to:mime-version; bh=NPfarDAD/cXVHdT8i9NUQCQb9TSUxoJY716AgVwU5A0=; b=pCB/R4VDpnJrx70WIBQig3xl+ZcWcIUk8Z1P1X5TAGmI3ZQqIsVXYWXGNFnHcL4kw7 RXXS03foBUHI/9SJwkaShAGO/DFuLBTeu5n2Vk3sBGL1JE88/C96bA3xAY7MM2eZGEWY MEsCxCejiXCtfW0jKBeqZ5hdIWHE/NAo7tFnrijYOPVnejSc0Axycp6dsoEYUBssSAV8 ZRDaoWt69lsFn0R4JKs2CmeSpkGpYJexSKnio6EHVYZAoEs1wkSGn4aPjP9W0JqlrgZF Q0jyr+/T1JzYxomnAze5ZYbDHc17MKQ65gFLZHLGw0I1xapxnudO7btEtfYKsdo1uc12 Zfgg== X-Gm-Message-State: AFeK/H1pFRppgpFqUgavvXBTaGV0Ti980wWP5bLBa672nyGHNE/RFIgrNmSn8dzbPAriYA== X-Received: by 10.28.178.84 with SMTP id b81mr3242427wmf.83.1489853431284; Sat, 18 Mar 2017 09:10:31 -0700 (PDT) X-Mailer: Apple Mail (2.3124) Xref: news.gmane.org gmane.linux.lib.musl.general:11162 Archived-At: --Apple-Mail=_D5123C47-ED3D-4140-89AA-173197A2E41C Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii I found several bugs in strptime: 1. tm_yday is off by one with %j (tm_yday range is 0-365 while %j is 1-366). 2. string pointer is not incremented when processing %p format. 3. calling strptime(..., "%C", tm), where tm->tm_year != 0, will result in a wrong value stored in tm_year. --Apple-Mail=_D5123C47-ED3D-4140-89AA-173197A2E41C Content-Disposition: attachment; filename=strptime-%j-off-by-one.patch Content-Type: application/octet-stream; name="strptime-%j-off-by-one.patch" Content-Transfer-Encoding: 7bit diff --git a/src/time/strptime.c b/src/time/strptime.c index 55c7ed1..da9e1f4 100644 --- a/src/time/strptime.c +++ b/src/time/strptime.c @@ -73,6 +73,7 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri dest = &tm->tm_yday; min = 1; range = 366; + adj = 1; goto numeric_range; case 'm': dest = &tm->tm_mon; --Apple-Mail=_D5123C47-ED3D-4140-89AA-173197A2E41C Content-Disposition: attachment; filename=strptime-fix-%p-fmt.patch Content-Type: application/octet-stream; name="strptime-fix-%p-fmt.patch" Content-Transfer-Encoding: 7bit diff --git a/src/time/strptime.c b/src/time/strptime.c index da9e1f4..cff0a7c 100644 --- a/src/time/strptime.c +++ b/src/time/strptime.c @@ -94,6 +94,7 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri len = strlen(ex); if (!strncasecmp(s, ex, len)) { tm->tm_hour %= 12; + s += len; break; } ex = nl_langinfo(PM_STR); @@ -101,6 +102,7 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri if (!strncasecmp(s, ex, len)) { tm->tm_hour %= 12; tm->tm_hour += 12; + s += len; break; } return 0; --Apple-Mail=_D5123C47-ED3D-4140-89AA-173197A2E41C Content-Disposition: attachment; filename=strptime-fix-%C-fmt.patch Content-Type: application/octet-stream; name="strptime-fix-%C-fmt.patch" Content-Transfer-Encoding: 7bit diff --git a/src/time/strptime.c b/src/time/strptime.c index cff0a7c..c54a0d8 100644 --- a/src/time/strptime.c +++ b/src/time/strptime.c @@ -11,7 +11,7 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri int i, w, neg, adj, min, range, *dest, dummy; const char *ex; size_t len; - int want_century = 0, century = 0; + int want_century = 0, century = 0, relyear = 0; while (*f) { if (*f != '%') { if (isspace(*f)) for (; *s && isspace(*s); s++); @@ -144,7 +144,7 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri if (!s) return 0; break; case 'y': - dest = &tm->tm_year; + dest = &relyear; w = 2; want_century |= 1; goto numeric_digits; @@ -198,6 +198,7 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri } } if (want_century) { + tm->tm_year = relyear; if (want_century & 2) tm->tm_year += century * 100 - 1900; else if (tm->tm_year <= 68) tm->tm_year += 100; } --Apple-Mail=_D5123C47-ED3D-4140-89AA-173197A2E41C Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii - Julien --Apple-Mail=_D5123C47-ED3D-4140-89AA-173197A2E41C--