lib: use Curl_str_number() for parsing decimal numbers

Instead of strtoul() and strtol() calls.

Easier API with better integer overflow detection and built-in max check
that now comes automatic everywhere this is used.

Closes #16319
This commit is contained in:
Daniel Stenberg 2025-02-13 08:45:43 +01:00
parent 130b6891c8
commit b696fc129b
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
16 changed files with 180 additions and 202 deletions

View file

@ -83,6 +83,7 @@
#include "share.h"
#include "strdup.h"
#include "version_win32.h"
#include "strparse.h"
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
@ -741,10 +742,9 @@ static CURLcode bindlocal(struct Curl_easy *data, struct connectdata *conn,
Curl_printable_address. The latter returns only numeric scope
IDs and the former returns none at all. So the scope ID, if
present, is known to be numeric */
unsigned long scope_id = strtoul(scope_ptr, NULL, 10);
if(scope_id > UINT_MAX)
size_t scope_id;
if(Curl_str_number((const char **)&scope_ptr, &scope_id, UINT_MAX))
return CURLE_UNSUPPORTED_PROTOCOL;
si6->sin6_scope_id = (unsigned int)scope_id;
}
#endif