]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
headers: remove assert from Curl_headers_push
authorDaniel Stenberg <daniel@haxx.se>
Tue, 16 Jan 2024 22:50:02 +0000 (23:50 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 19 Jan 2024 08:16:44 +0000 (09:16 +0100)
The fuzzer managed to reach the function without a terminating CR or LF
so let's handle it normally. While there, remove the goto.

Bug: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=65839

Closes #12721

lib/headers.c

index 9c29238993aec4fcef3b73c6e997c2342dc412b4..8a3264ab566c2b5a835053347c108d54bb0eb768 100644 (file)
@@ -291,9 +291,9 @@ CURLcode Curl_headers_push(struct Curl_easy *data, const char *header,
   end = strchr(header, '\r');
   if(!end) {
     end = strchr(header, '\n');
-    DEBUGASSERT(end);
     if(!end)
-      return CURLE_BAD_FUNCTION_ARGUMENT;
+      /* neither CR nor LF as terminator is not a valid header */
+      return CURLE_WEIRD_SERVER_REPLY;
   }
   hlen = end - header;
 
@@ -320,21 +320,19 @@ CURLcode Curl_headers_push(struct Curl_easy *data, const char *header,
   hs->buffer[hlen] = 0; /* nul terminate */
 
   result = namevalue(hs->buffer, hlen, type, &name, &value);
-  if(result)
-    goto fail;
-
-  hs->name = name;
-  hs->value = value;
-  hs->type = type;
-  hs->request = data->state.requests;
-
-  /* insert this node into the list of headers */
-  Curl_llist_insert_next(&data->state.httphdrs, data->state.httphdrs.tail,
-                         hs, &hs->node);
-  data->state.prevhead = hs;
-  return CURLE_OK;
-fail:
-  free(hs);
+  if(!result) {
+    hs->name = name;
+    hs->value = value;
+    hs->type = type;
+    hs->request = data->state.requests;
+
+    /* insert this node into the list of headers */
+    Curl_llist_insert_next(&data->state.httphdrs, data->state.httphdrs.tail,
+                           hs, &hs->node);
+    data->state.prevhead = hs;
+  }
+  else
+    free(hs);
   return result;
 }