tests/server: use curlx_str_numblanks() to avoid errno

Replacing `strtoul()` calls and glue code.

Closes #16671
This commit is contained in:
Viktor Szakats 2025-03-11 11:09:43 +01:00
parent 60b52c0c8b
commit 29ed1f9834
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
3 changed files with 13 additions and 24 deletions

View file

@ -106,5 +106,6 @@ void Curl_str_passblanks(const char **linep);
#define curlx_str_octal(x,y,z) Curl_str_octal(x,y,z)
#define curlx_str_single(x,y) Curl_str_single(x,y)
#define curlx_str_passblanks(x) Curl_str_passblanks(x)
#define curlx_str_numblanks(x,y) Curl_str_numblanks(x,y)
#endif /* HEADER_CURL_STRPARSE_H */

View file

@ -436,23 +436,17 @@ static int rtspd_ProcessRequest(struct rtspd_httprequest *req)
request including the body before we return. If we've been told to
ignore the content-length, we will return as soon as all headers
have been received */
char *endptr;
char *ptr = line + 15;
unsigned long clen = 0;
while(*ptr && ISSPACE(*ptr))
ptr++;
endptr = ptr;
CURL_SETERRNO(0);
clen = strtoul(ptr, &endptr, 10);
if((ptr == endptr) || !ISSPACE(*endptr) || (ERANGE == errno)) {
curl_off_t clen;
const char *p = line + strlen("Content-Length:");
if(curlx_str_numblanks(&p, &clen)) {
/* this assumes that a zero Content-Length is valid */
logmsg("Found invalid Content-Length: (%s) in the request", ptr);
logmsg("Found invalid '%s' in the request", line);
req->open = FALSE; /* closes connection */
return 1; /* done */
}
req->cl = clen - req->skip;
req->cl = (size_t)clen - req->skip;
logmsg("Found Content-Length: %lu in the request", clen);
logmsg("Found Content-Length: %zu in the request", (size_t)clen);
if(req->skip)
logmsg("... but will abort after %zu bytes", req->cl);
break;

View file

@ -588,26 +588,20 @@ static int sws_ProcessRequest(struct sws_httprequest *req)
request including the body before we return. If we've been told to
ignore the content-length, we will return as soon as all headers
have been received */
char *endptr;
char *ptr = line + 15;
unsigned long clen = 0;
while(*ptr && ISSPACE(*ptr))
ptr++;
endptr = ptr;
CURL_SETERRNO(0);
clen = strtoul(ptr, &endptr, 10);
if((ptr == endptr) || !ISSPACE(*endptr) || (ERANGE == errno)) {
curl_off_t clen;
const char *p = line + strlen("Content-Length:");
if(curlx_str_numblanks(&p, &clen)) {
/* this assumes that a zero Content-Length is valid */
logmsg("Found invalid Content-Length: (%s) in the request", ptr);
logmsg("Found invalid '%s' in the request", line);
req->open = FALSE; /* closes connection */
return 1; /* done */
}
if(req->skipall)
req->cl = 0;
else
req->cl = clen - req->skip;
req->cl = (size_t)clen - req->skip;
logmsg("Found Content-Length: %lu in the request", clen);
logmsg("Found Content-Length: %zu in the request", (size_t)clen);
if(req->skip)
logmsg("... but will abort after %zu bytes", req->cl);
}