diff --git a/lib/headers.c b/lib/headers.c
index 9f522ecc13..ec3ac7473c 100644
--- a/lib/headers.c
+++ b/lib/headers.c
@@ -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;
}
diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am
index f84eb8461d..33ba9b5b17 100644
--- a/tests/data/Makefile.am
+++ b/tests/data/Makefile.am
@@ -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
index 0000000000..68439f90cb
--- /dev/null
+++ b/tests/data/test749
@@ -0,0 +1,61 @@
+
+
+
+HTTP
+HTTP GET
+HTTP CONNECT
+HTTP proxy
+proxytunnel
+
+
+
+# Server-side
+
+
+# this is returned first since we get no proxy-auth
+
+HTTP/1.1 400 Bad request
+Connection: close
+
+
+
+
+HTTP/1.1 400 Bad request
+Connection: close
+
+
+
+
+# Client-side
+
+
+http
+
+
+proxy
+
+
+HTTP CONNECT with proxy returning 400 and closing
+
+
+http://test.example --proxy http://%HOSTIP:%HTTPPORT --proxytunnel -sS
+
+
+
+# Verify data after the test has been "shot"
+
+
+CONNECT test.example:80 HTTP/1.1
+Host: test.example:80
+User-Agent: curl/%VERSION
+Proxy-Connection: Keep-Alive
+
+
+
+56
+
+
+curl: (56) CONNECT tunnel failed, response 400
+
+
+
diff --git a/tests/data/test750 b/tests/data/test750
new file mode 100644
index 0000000000..7acc8d3181
--- /dev/null
+++ b/tests/data/test750
@@ -0,0 +1,57 @@
+
+
+
+HTTP
+HTTP GET
+HTTP CONNECT
+HTTP proxy
+proxytunnel
+
+
+
+# Server-side
+
+
+# this is returned first since we get no proxy-auth
+
+
+400 Bad request
+swsclose
+
+
+
+
+
+# Client-side
+
+
+http
+
+
+proxy
+
+
+HTTP CONNECT with proxy returning just HTML and closing
+
+
+http://test.example --proxy http://%HOSTIP:%HTTPPORT --proxytunnel -sS
+
+
+
+# Verify data after the test has been "shot"
+
+
+CONNECT test.example:80 HTTP/1.1
+Host: test.example:80
+User-Agent: curl/%VERSION
+Proxy-Connection: Keep-Alive
+
+
+
+43
+
+
+curl: (43) Invalid response header
+
+
+