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 <[email protected]> Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
5f4a1d9171
commit
18079f66df
@@ -3,6 +3,7 @@
|
||||
#include <string.h>
|
||||
#include <langinfo.h>
|
||||
#include <locale.h>
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
#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 {
|
||||
|
||||
Reference in New Issue
Block a user