| Summary: | strptime(3) doesn't increment pointer on parsing '%w' (weekday) | ||||||
|---|---|---|---|---|---|---|---|
| Product: | Base System | Reporter: | Michael Gmelin <grembo> | ||||
| Component: | kern | Assignee: | Andrey A. Chernov <ache> | ||||
| Status: | Closed FIXED | ||||||
| Severity: | Affects Only Me | CC: | ed | ||||
| Priority: | --- | Keywords: | patch | ||||
| Version: | 11.0-RC1 | Flags: | ache:
mfc-stable11?
ache: mfc-stable10? ache: mfc-stable9? |
||||
| Hardware: | Any | ||||||
| OS: | Any | ||||||
| Attachments: |
|
||||||
This also seems to affect older versions of FreeBSD (at least down to 9.x) Looks like this bug actually got fixed in r306075 by ache@, which is going to be MFCed soonish. Assigning this bug to him. A commit references this bug: Author: ache Date: Wed Sep 28 20:49:33 UTC 2016 New revision: 306414 URL: https://svnweb.freebsd.org/changeset/base/306414 Log: MFC r306075,r306109 1) Microoptimize %p case. 2) Implememt %u for GNU compatibility. 3) Don't forget to advance buf for %w/%u. 4) Fail with incomplete week (week 0) request and no such week in the year. 5) Fix yday formula when Sunday requested and the week started from Monday. 6) Fail with impossible yday for incomplete week (week 0) and direct %w/%u request. 7) Shift yday/wday to the first day of the year, if incomplete week (week 0) requested and no %w/%u used. 8) For already non-standard %z extension implement GNU compatible formats: +hh and -hh. 9) Check for incorrect values for %z. PR: 212983 (case 3 only) Changes: _U stable/10/ stable/10/lib/libc/stdtime/strptime.c A commit references this bug: Author: ache Date: Wed Sep 28 20:52:59 UTC 2016 New revision: 306415 URL: https://svnweb.freebsd.org/changeset/base/306415 Log: MFC r306075,r306109 1) Microoptimize %p case. 2) Implememt %u for GNU compatibility. 3) Don't forget to advance buf for %w/%u. 4) Fail with incomplete week (week 0) request and no such week in the year. 5) Fix yday formula when Sunday requested and the week started from Monday. 6) Fail with impossible yday for incomplete week (week 0) and direct %w/%u request. 7) Shift yday/wday to the first day of the year, if incomplete week (week 0) requested and no %w/%u used. 8) For already non-standard %z extension implement GNU compatible formats: +hh and -hh. 9) Check for incorrect values for %z. PR: 212983 (case 3 only) Changes: _U stable/11/ stable/11/lib/libc/stdtime/strptime.c A commit references this bug: Author: ache Date: Wed Sep 28 20:54:47 UTC 2016 New revision: 306416 URL: https://svnweb.freebsd.org/changeset/base/306416 Log: MFC r306075,r306109 1) Microoptimize %p case. 2) Implememt %u for GNU compatibility. 3) Don't forget to advance buf for %w/%u. 4) Fail with incomplete week (week 0) request and no such week in the year. 5) Fix yday formula when Sunday requested and the week started from Monday. 6) Fail with impossible yday for incomplete week (week 0) and direct %w/%u request. 7) Shift yday/wday to the first day of the year, if incomplete week (week 0) requested and no %w/%u used. 8) For already non-standard %z extension implement GNU compatible formats: +hh and -hh. 9) Check for incorrect values for %z. PR: 212983 (case 3 only) Changes: _U stable/9/ _U stable/9/lib/ _U stable/9/lib/libc/ _U stable/9/lib/libc/stdtime/ stable/9/lib/libc/stdtime/strptime.c |
Created attachment 175152 [details] Patch to increment buf on parsing 'w' strptime has a long standing bug that makes it fail to parse "%w" properly. E.g.: printf("%s", strptime("1970/01/01 00:00:00 4 UTC 123", "%Y/%m/%d %T %w UTC", &tm)); Expected output: 123 Actual output: 4123 or printf("%i", (int)strptime("4 1970", "%w %Y", &tm)); Expected output: Something >0 Actual output: 0 The attached patch aims to fix this problem. Thanks to Nikola Kolev for reporting this problem.