]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
http: reject spurious CR bytes in headers
authorDaniel Stenberg <daniel@haxx.se>
Sat, 6 Jun 2026 15:27:52 +0000 (17:27 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Sat, 6 Jun 2026 20:54:25 +0000 (22:54 +0200)
Verified by test 2105

Closes #21882

lib/http.c
tests/data/Makefile.am
tests/data/test2105 [new file with mode: 0644]

index e16d15a446ffef822df654a7604cfcd916117be4..f8ca40b0a4943b11fd205900964b449cae23bb4a 100644 (file)
@@ -3818,6 +3818,14 @@ static CURLcode verify_header(struct Curl_easy *data,
     failf(data, "Nul byte in header");
     return CURLE_WEIRD_SERVER_REPLY;
   }
+  if(hdlen > 2) {
+    ptr = memchr(hd, '\r', hdlen - 2);
+    if(ptr) {
+      /* CR may only precede the LF, nothing else */
+      failf(data, "Carriage return found in header");
+      return CURLE_WEIRD_SERVER_REPLY;
+    }
+  }
   if(k->headerline < 2)
     /* the first "header" is the status-line and it has no colon */
     return CURLE_OK;
index da4bdbfbce7aec22eddf293cf5c19737a5dab4e1..f04cac6ea4cb1c2ffd8a57be912d4e9bb518b3ef 100644 (file)
@@ -253,7 +253,7 @@ test2064 test2065 test2066 test2067 test2068 test2069 test2070 test2071 \
 test2072 test2073 test2074 test2075 test2076 test2077 test2078 test2079 \
 test2080 test2081 test2082 test2083 test2084 test2085 test2086 test2087 \
 test2088 test2089 test2090 test2091 test2092 \
-test2100 test2101 test2102 test2103 test2104 \
+test2100 test2101 test2102 test2103 test2104 test2105 \
 \
 test2200 test2201 test2202 test2203 test2204 test2205 test2206 test2207 \
 \
diff --git a/tests/data/test2105 b/tests/data/test2105
new file mode 100644 (file)
index 0000000..8bd26ca
--- /dev/null
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="US-ASCII"?>
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+</keywords>
+</info>
+
+# Server-side
+<reply>
+<data crlf="headers" nocheck="yes">
+HTTP/1.1 200 OK
+Date: Tue, 09 Nov 2010 14:49:00 GMT
+Server: test-server/%CRfake
+Content-Length: 6
+Funny-head: yesyes
+
+-foo-
+</data>
+</reply>
+
+# Client-side
+<client>
+<server>
+http
+</server>
+<name>
+HTTP with spurious CR in received header
+</name>
+<command>
+http://%HOSTIP:%HTTPPORT/%TESTNUMBER
+</command>
+</client>
+
+# Verify data after the test has been "shot"
+<verify>
+<protocol crlf="headers">
+GET /%TESTNUMBER HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+User-Agent: curl/%VERSION
+Accept: */*
+
+</protocol>
+<errorcode>
+8
+</errorcode>
+</verify>
+</testcase>