From f47a5d400b8ffa26cfc5b345dbff52fec94ac7f3 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Tue, 21 Nov 2023 16:33:15 -0500 Subject: 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. --- src/time/strftime.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/time/strftime.c b/src/time/strftime.c index cc53d536..ef590903 100644 --- a/src/time/strftime.c +++ b/src/time/strftime.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include "locale_impl.h" @@ -233,7 +234,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 { -- cgit v1.2.1