Bug 93197 - [libc] strptime(3) succeeds on formats it should fail on
Summary: [libc] strptime(3) succeeds on formats it should fail on
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 6.0-RELEASE
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-standards (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-11 20:00 UTC by mickey242
Modified: 2016-09-25 23:06 UTC (History)
3 users (show)

See Also:


Attachments
Possible fix (324 bytes, patch)
2014-09-28 21:33 UTC, Pedro F. Giffuni
no flags Details | Diff
Updated patch (569 bytes, patch)
2014-10-03 18:39 UTC, Pedro F. Giffuni
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description mickey242 2006-02-11 20:00:20 UTC
	The strptime(3) function succeeds with input that it should fail on according to the given format string.
	Excerpt from the strptime(3) manpage:
	   It returns NULL if one of the conversions failed.

How-To-Repeat: 	Compile and run this test program. strptime() should obviously fail on input 'March' cause format '%d'
	is not satisfied.
	
#include <stdio.h>
#include <time.h>

int main(int argc, char *argv[])
{
        struct tm tm;
        char *date="March";
        char *test=strptime(date, "%B %d", &tm);
                        
        if(test)
                printf("Broken\n");
        else
                printf("OK\n");

        return 0;
}
Comment 1 Pedro F. Giffuni freebsd_committer freebsd_triage 2014-09-28 21:33:42 UTC
Created attachment 147776 [details]
Possible fix

Suggested from ache@, while considering a different bug.
Comment 2 Pedro F. Giffuni freebsd_committer freebsd_triage 2014-09-28 21:50:58 UTC
Assign to standards: this looks like a POSIX compliance issue.

http://pubs.opengroup.org/onlinepubs/009695399/functions/strptime.html

...

RETURN VALUE

    Upon successful completion, strptime() shall return a pointer to the character following the last character parsed. Otherwise, a null pointer shall be returned.
Comment 3 Pedro F. Giffuni freebsd_committer freebsd_triage 2014-10-03 18:39:22 UTC
Created attachment 147941 [details]
Updated patch

Again from ache@ :

"... we need to return NULL on all currently unsupported formats, including mentioned ones and '\0'."
Comment 4 commit-hook freebsd_committer freebsd_triage 2014-10-07 06:34:33 UTC
A commit references this bug:

Author: ache
Date: Tue Oct  7 06:34:05 UTC 2014
New revision: 272679
URL: https://svnweb.freebsd.org/changeset/base/272679

Log:
  1) Fix the case we have less arguments for format string than we expected.
  2) Return error on unsupported format specs.
  (both according to POSIX)

  PR:     93197

Changes:
  head/lib/libc/stdtime/strptime.c
Comment 5 Pedro F. Giffuni freebsd_committer freebsd_triage 2014-10-08 16:40:20 UTC
r272679 (along r272678) should be MFC'd since they are necessary for POSIX compliance.
Comment 6 commit-hook freebsd_committer freebsd_triage 2014-10-19 21:16:57 UTC
A commit references this bug:

Author: ache
Date: Sun Oct 19 21:16:25 UTC 2014
New revision: 273290
URL: https://svnweb.freebsd.org/changeset/base/273290

Log:
  MFC r272562,r272678,r272679

  1) Fix the case we have less arguments for format string than we expected.
  2) Return error on unsupported format specs.
  (both according to POSIX)
  3) For %Z format, understand "UTC" name too.

  PR:     93197

Changes:
_U  stable/10/
  stable/10/lib/libc/stdtime/strptime.c
Comment 7 Andrey A. Chernov freebsd_committer freebsd_triage 2014-10-19 21:18:14 UTC
Committed into -stable
Comment 8 commit-hook freebsd_committer freebsd_triage 2016-09-25 23:06:21 UTC
A commit references this bug:

Author: ache
Date: Sun Sep 25 23:05:45 UTC 2016
New revision: 306326
URL: https://svnweb.freebsd.org/changeset/base/306326

Log:
  MFC r272562,r272678,r272679

  1) Fix the case we have less arguments for format string than we expected.
  2) Return error on unsupported format specs.
  (both according to POSIX)
  3) For %Z format, understand "UTC" name too.

  PR:     93197 (only r272679)

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