strparse: make Curl_str_number() return error for no digits

Closes #16319
This commit is contained in:
Daniel Stenberg 2025-02-14 08:46:26 +01:00
parent 5d194d942d
commit 130b6891c8
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
2 changed files with 5 additions and 2 deletions

View File

@ -110,7 +110,9 @@ int Curl_str_number(const char **linep, size_t *nump, size_t max)
size_t num = 0;
DEBUGASSERT(linep && *linep && nump);
*nump = 0;
while(ISDIGIT(**linep)) {
if(!ISDIGIT(**linep))
return STRE_NO_NUM;
do {
int n = **linep - '0';
if(num > ((SIZE_T_MAX - n) / 10))
return STRE_OVERFLOW;
@ -118,7 +120,7 @@ int Curl_str_number(const char **linep, size_t *nump, size_t max)
if(num > max)
return STRE_BIG; /** too big */
(*linep)++;
}
} while(ISDIGIT(**linep));
*nump = num;
return STRE_OK;
}

View File

@ -33,6 +33,7 @@
#define STRE_BYTE 5
#define STRE_NEWLINE 6
#define STRE_OVERFLOW 7
#define STRE_NO_NUM 8
struct Curl_str {
const char *str;