Bug 232072 - Parsing error with format "%d" in strptime(3)
Summary: Parsing error with format "%d" in strptime(3)
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: standards (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-standards (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-10-08 14:47 UTC by Miguel
Modified: 2018-10-15 10:50 UTC (History)
1 user (show)

See Also:


Attachments
Disallow zero day of month from strptime("%d"). (392 bytes, patch)
2018-10-08 16:22 UTC, Konstantin Belousov
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Miguel 2018-10-08 14:47:22 UTC
the format "%d" in the c function strptime(3) does not conform to what the documentation says (https://www.freebsd.org/cgi/man.cgi?query=strptime&sektion=3&manpath=freebsd-release-ports)

It is supposed to allow numbers between "01" and "31" but it also allows "00".
I am not sure if it is a bug or just the FreeBSD way of doing this function.
To my knowledge GNU has the fore mentioned behaviour.

Small c++ code to reproduce the error:

########################################################
#include<iostream>
#include<ctime>

int main()
{
       struct tm tm;
       if(strptime("00", "%d", &tm))
       {
               std::cout << "WRONG" << std::endl;
       }
       else
       {
               std::cout << "OK" << std::endl;
       }
}
########################################################

just execute 
clang++ main.cpp && ./a.out

EXPECTED:
OK

GOT:
WRONG
Comment 1 Konstantin Belousov freebsd_committer freebsd_triage 2018-10-08 16:21:46 UTC
Yes, both Linux and POSIX agree with your observation.
Comment 2 Konstantin Belousov freebsd_committer freebsd_triage 2018-10-08 16:22:30 UTC
Created attachment 197918 [details]
Disallow zero day of month from strptime("%d").
Comment 3 Miguel 2018-10-08 17:41:45 UTC
(In reply to Konstantin Belousov from comment #2)
Thanks for the quick response :)
Comment 4 commit-hook freebsd_committer freebsd_triage 2018-10-08 18:46:24 UTC
A commit references this bug:

Author: kib
Date: Mon Oct  8 18:45:41 UTC 2018
New revision: 339241
URL: https://svnweb.freebsd.org/changeset/base/339241

Log:
  Disallow zero day of month from strptime("%d").

  It is required by POSIX, specified in our man page, and followed by
  Linux.

  PR:	232072
  Reported by:	miguel_tete17@hotmail.com
  Sponsored by:	The FreeBSD Foundation
  Approved by:	re (gjb)
  MFC after:	1 week

Changes:
  head/lib/libc/stdtime/strptime.c
Comment 5 commit-hook freebsd_committer freebsd_triage 2018-10-15 10:50:14 UTC
A commit references this bug:

Author: kib
Date: Mon Oct 15 10:50:05 UTC 2018
New revision: 339359
URL: https://svnweb.freebsd.org/changeset/base/339359

Log:
  MFC r339241:
  Disallow zero day of month from strptime("%d").

  PR:	232072

Changes:
_U  stable/11/
  stable/11/lib/libc/stdtime/strptime.c