From 18079f66df69c0d67479cd558ae6038a6b099e89 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Tue, 21 Nov 2023 16:33:15 -0500 Subject: [PATCH] libroot/musl: strftime: don't attempt to parse field width without seeing a digit strtoul will consume leading whitespace or sign characters, which are not valid in this context, thereby accepting invalid field specifiers. so, avoid calling it unless there is a number to parse as the width. Change-Id: Ia683e6e8f71db8a323fec78555f3adef1bc90e6c Reviewed-on: https://review.haiku-os.org/c/haiku/+/9700 Reviewed-by: Adrien Destugues Tested-by: Commit checker robot --- src/system/libroot/posix/musl/time/strftime.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/system/libroot/posix/musl/time/strftime.c b/src/system/libroot/posix/musl/time/strftime.c index 7f3987bcda..3fe2e1a36f 100644 --- a/src/system/libroot/posix/musl/time/strftime.c +++ b/src/system/libroot/posix/musl/time/strftime.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include "locale_impl.h" @@ -235,7 +236,7 @@ size_t __strftime_l(char *restrict s, size_t n, const char *restrict f, const st pad = 0; if (*f == '-' || *f == '_' || *f == '0') pad = *f++; if ((plus = (*f == '+'))) f++; - width = strtoul(f, &p, 10); + width = isdigit(*f) ? strtoul(f, &p, 10) : 0; if (*p == 'C' || *p == 'F' || *p == 'G' || *p == 'Y') { if (!width && p!=f) width = 1; } else {