Description: fix URL request injection
Origin: backport, https://github.com/bagder/curl/commit/178bd7db34f77e020fb8562890c5625ccbd67093
Origin: backport, https://github.com/bagder/curl/commit/3df8e78860d3a3d3cf95252bd2b4ad5fd53360cd

Index: curl-7.35.0/lib/url.c
===================================================================
--- curl-7.35.0.orig/lib/url.c	2015-01-14 08:48:08.506540363 -0500
+++ curl-7.35.0/lib/url.c	2015-01-14 08:48:08.502540334 -0500
@@ -3710,6 +3710,13 @@
 
   *prot_missing = FALSE;
 
+  /* We might pass the entire URL into the request so we need to make sure
+   * there are no bad characters in there.*/
+  if(strpbrk(data->change.url, "\r\n")) {
+    failf(data, "Illegal characters found in URL");
+    return CURLE_URL_MALFORMAT;
+  }
+
   /*************************************************************
    * Parse the URL.
    *
Index: curl-7.35.0/tests/data/Makefile.am
===================================================================
--- curl-7.35.0.orig/tests/data/Makefile.am	2015-01-14 08:48:08.506540363 -0500
+++ curl-7.35.0/tests/data/Makefile.am	2015-01-14 08:48:35.486745922 -0500
@@ -123,7 +123,7 @@
 test1416 test1417 test1418 test1419 \
 \
 test1500 test1501 test1502 test1503 test1504 test1505 test1506 test1507 \
-test1508 test1509 test1510 test1511 test1512 test1513 test1514 \
+test1508 test1509 test1510 test1511 test1512 test1513 test1514 test1529 \
 \
 test1900 test1901 test1902 test1903 \
 \
Index: curl-7.35.0/tests/data/test1529
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ curl-7.35.0/tests/data/test1529	2015-01-14 08:48:08.502540334 -0500
@@ -0,0 +1,43 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+HTTP proxy
+</keywords>
+</info>
+
+# Server-side
+<reply>
+<connect>
+HTTP/1.1 200 OK
+We-are: good
+
+</connect>
+
+</reply>
+# Client-side
+<client>
+<server>
+http
+http-proxy
+</server>
+<tool>
+lib1529
+</tool>
+ <name>
+HTTP request-injection in URL sent over proxy
+ </name>
+ <command>
+ "http://the.old.moo:%HTTPPORT/1529" %HOSTIP:%PROXYPORT
+</command>
+</client>
+
+# it should be detected and an error should be reported
+<verify>
+# 3 == CURLE_URL_MALFORMAT
+<errorcode>
+3
+</errorcode>
+</verify>
+</testcase>
Index: curl-7.35.0/tests/libtest/Makefile.inc
===================================================================
--- curl-7.35.0.orig/tests/libtest/Makefile.inc	2015-01-14 08:48:08.506540363 -0500
+++ curl-7.35.0/tests/libtest/Makefile.inc	2015-01-14 08:48:45.318820813 -0500
@@ -21,7 +21,7 @@
  lib571 lib572 lib573 lib574 lib575 lib576        lib578 lib579 lib582   \
  lib583 lib585 lib586 lib587        lib590 lib591 lib597 lib598 lib599   \
  lib1500 lib1501 lib1502 lib1503 lib1504 lib1505 lib1506 lib1507 lib1508 \
- lib1509 lib1510 lib1511 lib1512 lib1513 lib1514 \
+ lib1509 lib1510 lib1511 lib1512 lib1513 lib1514 lib1529 \
  lib1900 \
  lib2033
 
@@ -351,6 +351,10 @@
 lib1514_LDADD = $(TESTUTIL_LIBS)
 lib1514_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1514
 
+lib1529_SOURCES = lib1529.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
+lib1529_LDADD = $(TESTUTIL_LIBS)
+lib1529_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1529
+
 lib1900_SOURCES = lib1900.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
 lib1900_LDADD = $(TESTUTIL_LIBS)
 lib1900_CPPFLAGS = $(AM_CPPFLAGS)
Index: curl-7.35.0/tests/libtest/lib1529.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ curl-7.35.0/tests/libtest/lib1529.c	2015-01-14 08:48:08.502540334 -0500
@@ -0,0 +1,59 @@
+/***************************************************************************
+ *                                  _   _ ____  _
+ *  Project                     ___| | | |  _ \| |
+ *                             / __| | | | |_) | |
+ *                            | (__| |_| |  _ <| |___
+ *                             \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ***************************************************************************/
+
+#include "test.h"
+
+#include "memdebug.h"
+
+int test(char *URL)
+{
+  CURL *curl = NULL;
+  CURLcode res = CURLE_FAILED_INIT;
+  char bURL[512];
+  snprintf(bURL, sizeof(bURL), "%s HTTP/1.1\r\nGET http://1529.com/1529", URL);
+
+  if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
+    fprintf(stderr, "curl_global_init() failed\n");
+    return TEST_ERR_MAJOR_BAD;
+  }
+
+  if((curl = curl_easy_init()) == NULL) {
+    fprintf(stderr, "curl_easy_init() failed\n");
+    curl_global_cleanup();
+    return TEST_ERR_MAJOR_BAD;
+  }
+
+  test_setopt(curl, CURLOPT_URL, bURL);
+  test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
+  test_setopt(curl, CURLOPT_VERBOSE, 1L);
+  test_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
+  test_setopt(curl, CURLOPT_HEADER, 1L);
+
+  res = curl_easy_perform(curl);
+
+test_cleanup:
+
+  curl_easy_cleanup(curl);
+  curl_global_cleanup();
+
+  return (int)res;
+}
