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; }
Created attachment 147776 [details] Possible fix Suggested from ache@, while considering a different bug.
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.
Created attachment 147941 [details] Updated patch Again from ache@ : "... we need to return NULL on all currently unsupported formats, including mentioned ones and '\0'."
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
r272679 (along r272678) should be MFC'd since they are necessary for POSIX compliance.
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
Committed into -stable
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