]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
headers: set an error message on illegal response headers
authorDaniel Stenberg <daniel@haxx.se>
Tue, 13 May 2025 09:19:40 +0000 (11:19 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 13 May 2025 12:15:05 +0000 (14:15 +0200)
Makes it report "Invalid response header" instead of the slightly odd "A
libcurl function was given a bad argument".

Add test 749 and 750 for more CONNECT response testing.

Reported-by: Int64x86 on github
Fixes #17330
Closes #17336

lib/headers.c
tests/data/Makefile.am
tests/data/test749 [new file with mode: 0644]
tests/data/test750 [new file with mode: 0644]

index 9f522ecc1318dba818316698f8ff239741443371..ec3ac7473cc02375350ff384dc24b6d8eb9bf1dd 100644 (file)
@@ -336,8 +336,10 @@ CURLcode Curl_headers_push(struct Curl_easy *data, const char *header,
     Curl_llist_append(&data->state.httphdrs, hs, &hs->node);
     data->state.prevhead = hs;
   }
-  else
+  else {
+    failf(data, "Invalid response header");
     free(hs);
+  }
   return result;
 }
 
index f84eb8461dde293c1a59c0f2c0aad579f5bf68d6..33ba9b5b17125bb7607fa801ce66dbe857ffd5d4 100644 (file)
@@ -107,7 +107,7 @@ test709 test710 test711 test712 test713 test714 test715 test716 test717 \
 test718 test719 test720 test721 test722 test723 test724 test725 test726 \
 test727 test728 test729 test730 test731 test732 test733 test734 test735 \
 test736 test737 test738 test739 test740 test741 test742 test743 test744 \
-test745 test746 test747 test748 \
+test745 test746 test747 test748 test749 test750 \
 \
 test780 test781 test782 test783 test784 test785 test786 test787 test788 \
 test789 test790 test791 \
diff --git a/tests/data/test749 b/tests/data/test749
new file mode 100644 (file)
index 0000000..68439f9
--- /dev/null
@@ -0,0 +1,61 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+HTTP CONNECT
+HTTP proxy
+proxytunnel
+</keywords>
+</info>
+
+# Server-side
+<reply>
+
+# this is returned first since we get no proxy-auth
+<connect>
+HTTP/1.1 400 Bad request\r
+Connection: close\r
+\r
+</connect>
+
+<datacheck crlf="yes">
+HTTP/1.1 400 Bad request
+Connection: close
+
+</datacheck>
+</reply>
+
+# Client-side
+<client>
+<server>
+http
+</server>
+<features>
+proxy
+</features>
+<name>
+HTTP CONNECT with proxy returning 400 and closing
+</name>
+<command>
+http://test.example --proxy http://%HOSTIP:%HTTPPORT --proxytunnel -sS
+</command>
+</client>
+
+# Verify data after the test has been "shot"
+<verify>
+<protocol crlf="yes">
+CONNECT test.example:80 HTTP/1.1
+Host: test.example:80
+User-Agent: curl/%VERSION
+Proxy-Connection: Keep-Alive
+
+</protocol>
+<errorcode>
+56
+</errorcode>
+<stderr mode="text">
+curl: (56) CONNECT tunnel failed, response 400
+</stderr>
+</verify>
+</testcase>
diff --git a/tests/data/test750 b/tests/data/test750
new file mode 100644 (file)
index 0000000..7acc8d3
--- /dev/null
@@ -0,0 +1,57 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+HTTP CONNECT
+HTTP proxy
+proxytunnel
+</keywords>
+</info>
+
+# Server-side
+<reply>
+
+# this is returned first since we get no proxy-auth
+<connect>
+<html>
+<h1>400 Bad request</h1>
+swsclose
+</html>
+</connect>
+
+</reply>
+
+# Client-side
+<client>
+<server>
+http
+</server>
+<features>
+proxy
+</features>
+<name>
+HTTP CONNECT with proxy returning just HTML and closing
+</name>
+<command>
+http://test.example --proxy http://%HOSTIP:%HTTPPORT --proxytunnel -sS
+</command>
+</client>
+
+# Verify data after the test has been "shot"
+<verify>
+<protocol crlf="yes">
+CONNECT test.example:80 HTTP/1.1
+Host: test.example:80
+User-Agent: curl/%VERSION
+Proxy-Connection: Keep-Alive
+
+</protocol>
+<errorcode>
+43
+</errorcode>
+<stderr mode="text">
+curl: (43) Invalid response header
+</stderr>
+</verify>
+</testcase>