]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
lib: fix two curlx_strtoofft invokes bagder/strtoofft-checks 16548/head
authorDaniel Stenberg <daniel@haxx.se>
Mon, 3 Mar 2025 21:40:43 +0000 (22:40 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 3 Mar 2025 21:40:43 +0000 (22:40 +0100)
- cf-h1-proxy: check return code and return error if the parser fails

- http: make the Retry-After parser check for a date string first then
  number to avoid mis-parsing the begining of a date as a number

lib/cf-h1-proxy.c
lib/http.c

index e2f86fc1f2c383bea55f9c30d4a06488ea7a03bf..4698f014a71709ceeb93514539cc646d382cbacb 100644 (file)
@@ -315,8 +315,11 @@ static CURLcode on_resp_header(struct Curl_cfilter *cf,
             k->httpcode);
     }
     else {
-      (void)curlx_strtoofft(header + strlen("Content-Length:"),
-                            NULL, 10, &ts->cl);
+      if(curlx_strtoofft(header + strlen("Content-Length:"),
+                         NULL, 10, &ts->cl)) {
+        failf(data, "Unsupported Content-Length value");
+        return CURLE_WEIRD_SERVER_REPLY;
+      }
     }
   }
   else if(Curl_compareheader(header,
index af05cf6bd0c62de0a23f2b36b945c2b8a56ac0b4..8a9fe6e887c4e76986308002cedd6fdff5c4eb92 100644 (file)
@@ -3228,18 +3228,22 @@ static CURLcode http_header(struct Curl_easy *data,
     if(v) {
       /* Retry-After = HTTP-date / delay-seconds */
       curl_off_t retry_after = 0; /* zero for unknown or "now" */
-      /* Try it as a decimal number, if it works it is not a date */
-      (void)curlx_strtoofft(v, NULL, 10, &retry_after);
-      if(!retry_after) {
-        time_t date = Curl_getdate_capped(v);
+      time_t date;
+      Curl_str_passblanks(&v);
+
+      /* try it as a date first, because a date can otherwise start with and
+         get treated as a number */
+      date = Curl_getdate_capped(v);
+
+      if((time_t)-1 != date) {
         time_t current = time(NULL);
-        if((time_t)-1 != date && date > current) {
+        if(date >= current)
           /* convert date to number of seconds into the future */
           retry_after = date - current;
-        }
       }
-      if(retry_after < 0)
-        retry_after = 0;
+      else
+        /* Try it as a decimal number */
+        Curl_str_number(&v, &retry_after, CURL_OFF_T_MAX);
       /* limit to 6 hours max. this is not documented so that it can be changed
          in the future if necessary. */
       if(retry_after > 21600)