* [PATCH] strptime fixes
@ 2017-03-18 16:10 Julien Ramseier
2017-03-21 16:38 ` Rich Felker
0 siblings, 1 reply; 2+ messages in thread
From: Julien Ramseier @ 2017-03-18 16:10 UTC (permalink / raw)
To: musl
[-- Attachment #1: Type: text/plain, Size: 288 bytes --]
I found several bugs in strptime:
1. tm_yday is off by one with %j (tm_yday range is 0-365 while %j is 1-366).
2. string pointer is not incremented when processing %p format.
3. calling strptime(..., "%C", tm), where tm->tm_year != 0, will result in a
wrong value stored in tm_year.
[-- Attachment #2: strptime-%j-off-by-one.patch --]
[-- Type: application/octet-stream, Size: 365 bytes --]
diff --git a/src/time/strptime.c b/src/time/strptime.c
index 55c7ed1..da9e1f4 100644
--- a/src/time/strptime.c
+++ b/src/time/strptime.c
@@ -73,6 +73,7 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
dest = &tm->tm_yday;
min = 1;
range = 366;
+ adj = 1;
goto numeric_range;
case 'm':
dest = &tm->tm_mon;
[-- Attachment #3: strptime-fix-%p-fmt.patch --]
[-- Type: application/octet-stream, Size: 613 bytes --]
diff --git a/src/time/strptime.c b/src/time/strptime.c
index da9e1f4..cff0a7c 100644
--- a/src/time/strptime.c
+++ b/src/time/strptime.c
@@ -94,6 +94,7 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
len = strlen(ex);
if (!strncasecmp(s, ex, len)) {
tm->tm_hour %= 12;
+ s += len;
break;
}
ex = nl_langinfo(PM_STR);
@@ -101,6 +102,7 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
if (!strncasecmp(s, ex, len)) {
tm->tm_hour %= 12;
tm->tm_hour += 12;
+ s += len;
break;
}
return 0;
[-- Attachment #4: strptime-fix-%C-fmt.patch --]
[-- Type: application/octet-stream, Size: 1018 bytes --]
diff --git a/src/time/strptime.c b/src/time/strptime.c
index cff0a7c..c54a0d8 100644
--- a/src/time/strptime.c
+++ b/src/time/strptime.c
@@ -11,7 +11,7 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
int i, w, neg, adj, min, range, *dest, dummy;
const char *ex;
size_t len;
- int want_century = 0, century = 0;
+ int want_century = 0, century = 0, relyear = 0;
while (*f) {
if (*f != '%') {
if (isspace(*f)) for (; *s && isspace(*s); s++);
@@ -144,7 +144,7 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
if (!s) return 0;
break;
case 'y':
- dest = &tm->tm_year;
+ dest = &relyear;
w = 2;
want_century |= 1;
goto numeric_digits;
@@ -198,6 +198,7 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
}
}
if (want_century) {
+ tm->tm_year = relyear;
if (want_century & 2) tm->tm_year += century * 100 - 1900;
else if (tm->tm_year <= 68) tm->tm_year += 100;
}
[-- Attachment #5: Type: text/plain, Size: 13 bytes --]
- Julien
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] strptime fixes
2017-03-18 16:10 [PATCH] strptime fixes Julien Ramseier
@ 2017-03-21 16:38 ` Rich Felker
0 siblings, 0 replies; 2+ messages in thread
From: Rich Felker @ 2017-03-21 16:38 UTC (permalink / raw)
To: musl
On Sat, Mar 18, 2017 at 05:10:28PM +0100, Julien Ramseier wrote:
> I found several bugs in strptime:
>
> 1. tm_yday is off by one with %j (tm_yday range is 0-365 while %j is 1-366).
> 2. string pointer is not incremented when processing %p format.
> 3. calling strptime(..., "%C", tm), where tm->tm_year != 0, will result in a
> wrong value stored in tm_year.
>
These all look fine, committing.
Rich
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-03-21 16:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-18 16:10 [PATCH] strptime fixes Julien Ramseier
2017-03-21 16:38 ` Rich Felker
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).