]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tests/server: use `curlx_str_numblanks()` to avoid `errno`
authorViktor Szakats <commit@vsz.me>
Tue, 11 Mar 2025 10:09:43 +0000 (11:09 +0100)
committerViktor Szakats <commit@vsz.me>
Tue, 11 Mar 2025 15:06:33 +0000 (16:06 +0100)
Replacing `strtoul()` calls and glue code.

Closes #16671

lib/strparse.h
tests/server/rtspd.c
tests/server/sws.c

index 739ea31a17442f31b723a2ff58945cb8b0e5bae7..ebad485259fcc287e47b07405a03b41dd8ee9354 100644 (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 */
index 73e83f1589534eb1ec717e59310433e0d4db9a93..b8a066c43b3cd763f30b11b0a157d08145428541 100644 (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;
index fcc07160380ca0d246c784ac655cb11fa97faa64..5a1d46a07baac35cf0f6c3b4b3ab04639fa3a2bb 100644 (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);
     }