From: Julien Ramseier <j.ramseier@gmail.com>
To: musl@lists.openwall.com
Subject: [PATCH] strptime fixes
Date: Sat, 18 Mar 2017 17:10:28 +0100 [thread overview]
Message-ID: <25C67107-1C11-4606-9171-051707D92278@gmail.com> (raw)
[-- 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
next reply other threads:[~2017-03-18 16:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-18 16:10 Julien Ramseier [this message]
2017-03-21 16:38 ` Rich Felker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=25C67107-1C11-4606-9171-051707D92278@gmail.com \
--to=j.ramseier@gmail.com \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).