]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
http_proxy: parse the status line without sscanf
authorDaniel Stenberg <daniel@haxx.se>
Fri, 24 Feb 2023 11:39:26 +0000 (12:39 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 24 Feb 2023 22:54:54 +0000 (23:54 +0100)
Closes #10602

lib/http_proxy.c

index fdd092d03408b694cdf283d80e6ac95b5009daf4..9f214a305e834b9afecfdf5e1da1cafbf1a1f14a 100644 (file)
@@ -403,7 +403,6 @@ static CURLcode on_resp_header(struct Curl_cfilter *cf,
 {
   CURLcode result = CURLE_OK;
   struct SingleRequest *k = &data->req;
-  int subversion = 0;
   (void)cf;
 
   if((checkprefix("WWW-Authenticate:", header) &&
@@ -461,11 +460,14 @@ static CURLcode on_resp_header(struct Curl_cfilter *cf,
                              STRCONST("Proxy-Connection:"),
                              STRCONST("close")))
     ts->close_connection = TRUE;
-  else if(2 == sscanf(header, "HTTP/1.%d %d",
-                      &subversion,
-                      &k->httpcode)) {
+  else if(!strncmp(header, "HTTP/1.", 7) &&
+          ((header[7] == '0') || (header[7] == '1')) &&
+          (header[8] == ' ') &&
+          ISDIGIT(header[9]) && ISDIGIT(header[10]) && ISDIGIT(header[11]) &&
+          !ISDIGIT(header[12])) {
     /* store the HTTP code from the proxy */
-    data->info.httpproxycode = k->httpcode;
+    data->info.httpproxycode =  k->httpcode = (header[9] - '0') * 100 +
+      (header[10] - '0') * 10 + (header[11] - '0');
   }
   return result;
 }