Bug 212983

Summary: strptime(3) doesn't increment pointer on parsing '%w' (weekday)
Product: Base System Reporter: Michael Gmelin <grembo>
Component: kernAssignee: Andrey A. Chernov <ache>
Status: Closed FIXED    
Severity: Affects Only Me CC: ed
Priority: --- Keywords: patch
Version: 11.0-RC1Flags: ache: mfc-stable11?
ache: mfc-stable10?
ache: mfc-stable9?
Hardware: Any   
OS: Any   
Attachments:
Description Flags
Patch to increment buf on parsing 'w' none

Description Michael Gmelin freebsd_committer freebsd_triage 2016-09-25 10:58:47 UTC
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.
Comment 1 Michael Gmelin freebsd_committer freebsd_triage 2016-09-25 10:59:17 UTC
This also seems to affect older versions of FreeBSD (at least down to 9.x)
Comment 2 Ed Schouten freebsd_committer freebsd_triage 2016-09-25 14:10:24 UTC
Looks like this bug actually got fixed in r306075 by ache@, which is going to be MFCed soonish. Assigning this bug to him.
Comment 3 commit-hook freebsd_committer freebsd_triage 2016-09-28 20:49:56 UTC
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
Comment 4 commit-hook freebsd_committer freebsd_triage 2016-09-28 20:53:59 UTC
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
Comment 5 commit-hook freebsd_committer freebsd_triage 2016-09-28 20:55:02 UTC
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