Blame SOURCES/0022-curl-7.76.1-CVE-2022-32221.patch

7517dd
From 08a53016db649bdf4f65c42a9704d35e052be7eb Mon Sep 17 00:00:00 2001
7517dd
From: Daniel Stenberg <daniel@haxx.se>
7517dd
Date: Thu, 15 Sep 2022 09:22:45 +0200
7517dd
Subject: [PATCH 1/2] setopt: when POST is set, reset the 'upload' field
7517dd
7517dd
Reported-by: RobBotic1 on github
7517dd
Fixes #9507
7517dd
Closes #9511
7517dd
7517dd
Upstream-commit: a64e3e59938abd7d667e4470a18072a24d7e9de9
7517dd
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
7517dd
---
7517dd
 lib/setopt.c | 1 +
7517dd
 1 file changed, 1 insertion(+)
7517dd
7517dd
diff --git a/lib/setopt.c b/lib/setopt.c
7517dd
index d5e3b50..b8793b4 100644
7517dd
--- a/lib/setopt.c
7517dd
+++ b/lib/setopt.c
7517dd
@@ -628,6 +628,7 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
7517dd
     }
7517dd
     else
7517dd
       data->set.method = HTTPREQ_GET;
7517dd
+    data->set.upload = FALSE;
7517dd
     break;
7517dd
 
7517dd
   case CURLOPT_HTTPPOST:
7517dd
-- 
7517dd
2.37.3
7517dd
7517dd
7517dd
From a5e36349807b98d31a16bd220f6434289465e16a Mon Sep 17 00:00:00 2001
7517dd
From: Daniel Stenberg <daniel@haxx.se>
7517dd
Date: Thu, 15 Sep 2022 09:23:33 +0200
7517dd
Subject: [PATCH 2/2] test1948: verify PUT + POST reusing the same handle
7517dd
7517dd
Reproduced #9507, verifies the fix
7517dd
7517dd
Upstream-commit: 1edb15925e350be3b891f8a8de86600b22c0bb20
7517dd
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
7517dd
---
7517dd
 tests/data/Makefile.inc    |  1 +
7517dd
 tests/data/test1948        | 73 +++++++++++++++++++++++++++++++++++
7517dd
 tests/libtest/Makefile.inc |  5 +++
7517dd
 tests/libtest/lib1948.c    | 79 ++++++++++++++++++++++++++++++++++++++
7517dd
 4 files changed, 158 insertions(+)
7517dd
 create mode 100644 tests/data/test1948
7517dd
 create mode 100644 tests/libtest/lib1948.c
7517dd
7517dd
diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc
7517dd
index 818ee08..0cfab9b 100644
7517dd
--- a/tests/data/Makefile.inc
7517dd
+++ b/tests/data/Makefile.inc
7517dd
@@ -217,6 +217,7 @@ test1908 test1909 test1910 test1911 test1912 test1913 test1914 test1915 \
7517dd
 test1916 test1917 test1918 \
7517dd
 \
7517dd
 test1933 test1934 test1935 test1936 \
7517dd
+test1948 \
7517dd
 \
7517dd
 test2000 test2001 test2002 test2003 test2004 test2005 test2006 test2007 \
7517dd
 test2008 test2009 test2010 test2011 test2012 test2013 test2014 test2015 \
7517dd
diff --git a/tests/data/test1948 b/tests/data/test1948
7517dd
new file mode 100644
7517dd
index 0000000..639523d
7517dd
--- /dev/null
7517dd
+++ b/tests/data/test1948
7517dd
@@ -0,0 +1,73 @@
7517dd
+<testcase>
7517dd
+<info>
7517dd
+<keywords>
7517dd
+HTTP
7517dd
+HTTP POST
7517dd
+HTTP PUT
7517dd
+</keywords>
7517dd
+</info>
7517dd
+
7517dd
+# Server-side
7517dd
+<reply>
7517dd
+<data>
7517dd
+HTTP/1.1 200 OK
7517dd
+Date: Thu, 01 Nov 2001 14:49:00 GMT
7517dd
+Content-Type: text/html
7517dd
+Content-Length: 6
7517dd
+
7517dd
+hello
7517dd
+</data>
7517dd
+<datacheck>
7517dd
+HTTP/1.1 200 OK
7517dd
+Date: Thu, 01 Nov 2001 14:49:00 GMT
7517dd
+Content-Type: text/html
7517dd
+Content-Length: 6
7517dd
+
7517dd
+hello
7517dd
+HTTP/1.1 200 OK
7517dd
+Date: Thu, 01 Nov 2001 14:49:00 GMT
7517dd
+Content-Type: text/html
7517dd
+Content-Length: 6
7517dd
+
7517dd
+hello
7517dd
+</datacheck>
7517dd
+</reply>
7517dd
+
7517dd
+# Client-side
7517dd
+<client>
7517dd
+<server>
7517dd
+http
7517dd
+</server>
7517dd
+
7517dd
+<name>
7517dd
+CURLOPT_POST after CURLOPT_UPLOAD reusing handle
7517dd
+</name>
7517dd
+<tool>
7517dd
+lib%TESTNUMBER
7517dd
+</tool>
7517dd
+
7517dd
+<command>
7517dd
+http://%HOSTIP:%HTTPPORT/%TESTNUMBER
7517dd
+</command>
7517dd
+</client>
7517dd
+
7517dd
+# Verify data after the test has been "shot"
7517dd
+<verify>
7517dd
+<protocol>
7517dd
+PUT /%TESTNUMBER HTTP/1.1
7517dd
+Host: %HOSTIP:%HTTPPORT
7517dd
+Accept: */*
7517dd
+Content-Length: 22
7517dd
+Expect: 100-continue
7517dd
+
7517dd
+This is test PUT data
7517dd
+POST /1948 HTTP/1.1
7517dd
+Host: %HOSTIP:%HTTPPORT
7517dd
+Accept: */*
7517dd
+Content-Length: 22
7517dd
+Content-Type: application/x-www-form-urlencoded
7517dd
+
7517dd
+This is test PUT data
7517dd
+</protocol>
7517dd
+</verify>
7517dd
+</testcase>
7517dd
diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc
7517dd
index 83a8af4..3192eca 100644
7517dd
--- a/tests/libtest/Makefile.inc
7517dd
+++ b/tests/libtest/Makefile.inc
7517dd
@@ -61,6 +61,7 @@ noinst_PROGRAMS = chkhostname libauthretry libntlmconnect                \
7517dd
  lib1591 lib1592 lib1593 lib1594 lib1596 \
7517dd
          lib1905 lib1906 lib1907 lib1908 lib1910 lib1911 lib1912 lib1913 \
7517dd
          lib1915 lib1916 lib1917 lib1918 lib1933 lib1934 lib1935 lib1936 \
7517dd
+ lib1948 \
7517dd
          lib3010
7517dd
 
7517dd
 chkdecimalpoint_SOURCES = chkdecimalpoint.c ../../lib/mprintf.c \
7517dd
@@ -690,6 +691,10 @@ lib1936_SOURCES = lib1936.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
7517dd
 lib1936_LDADD = $(TESTUTIL_LIBS)
7517dd
 lib1936_CPPFLAGS = $(AM_CPPFLAGS)
7517dd
 
7517dd
+lib1948_SOURCES = lib1948.c $(SUPPORTFILES)
7517dd
+lib1948_LDADD = $(TESTUTIL_LIBS)
7517dd
+lib1948_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1948
7517dd
+
7517dd
 lib3010_SOURCES = lib3010.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
7517dd
 lib3010_LDADD = $(TESTUTIL_LIBS)
7517dd
 lib3010_CPPFLAGS = $(AM_CPPFLAGS)
7517dd
diff --git a/tests/libtest/lib1948.c b/tests/libtest/lib1948.c
7517dd
new file mode 100644
7517dd
index 0000000..7c891a2
7517dd
--- /dev/null
7517dd
+++ b/tests/libtest/lib1948.c
7517dd
@@ -0,0 +1,79 @@
7517dd
+/***************************************************************************
7517dd
+ *                                  _   _ ____  _
7517dd
+ *  Project                     ___| | | |  _ \| |
7517dd
+ *                             / __| | | | |_) | |
7517dd
+ *                            | (__| |_| |  _ <| |___
7517dd
+ *                             \___|\___/|_| \_\_____|
7517dd
+ *
7517dd
+ * Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
7517dd
+ *
7517dd
+ * This software is licensed as described in the file COPYING, which
7517dd
+ * you should have received as part of this distribution. The terms
7517dd
+ * are also available at https://curl.haxx.se/docs/copyright.html.
7517dd
+ *
7517dd
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
7517dd
+ * copies of the Software, and permit persons to whom the Software is
7517dd
+ * furnished to do so, under the terms of the COPYING file.
7517dd
+ *
7517dd
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
7517dd
+ * KIND, either express or implied.
7517dd
+ *
7517dd
+ * SPDX-License-Identifier: curl
7517dd
+ *
7517dd
+ ***************************************************************************/
7517dd
+
7517dd
+#include "test.h"
7517dd
+
7517dd
+typedef struct
7517dd
+{
7517dd
+  char *buf;
7517dd
+  size_t len;
7517dd
+} put_buffer;
7517dd
+
7517dd
+static size_t put_callback(char *ptr, size_t size, size_t nmemb, void *stream)
7517dd
+{
7517dd
+  put_buffer *putdata = (put_buffer *)stream;
7517dd
+  size_t totalsize = size * nmemb;
7517dd
+  size_t tocopy = (putdata->len < totalsize) ? putdata->len : totalsize;
7517dd
+  memcpy(ptr, putdata->buf, tocopy);
7517dd
+  putdata->len -= tocopy;
7517dd
+  putdata->buf += tocopy;
7517dd
+  return tocopy;
7517dd
+}
7517dd
+
7517dd
+int test(char *URL)
7517dd
+{
7517dd
+  CURL *curl;
7517dd
+  CURLcode res = CURLE_OUT_OF_MEMORY;
7517dd
+
7517dd
+  curl_global_init(CURL_GLOBAL_DEFAULT);
7517dd
+
7517dd
+  curl = curl_easy_init();
7517dd
+  if(curl) {
7517dd
+    const char *testput = "This is test PUT data\n";
7517dd
+    put_buffer pbuf;
7517dd
+
7517dd
+    /* PUT */
7517dd
+    curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
7517dd
+    curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
7517dd
+    curl_easy_setopt(curl, CURLOPT_READFUNCTION, put_callback);
7517dd
+    pbuf.buf = (char *)testput;
7517dd
+    pbuf.len = strlen(testput);
7517dd
+    curl_easy_setopt(curl, CURLOPT_READDATA, &pbuf);
7517dd
+    curl_easy_setopt(curl, CURLOPT_INFILESIZE, (long)strlen(testput));
7517dd
+    res = curl_easy_setopt(curl, CURLOPT_URL, URL);
7517dd
+    if(!res)
7517dd
+      res = curl_easy_perform(curl);
7517dd
+    if(!res) {
7517dd
+      /* POST */
7517dd
+      curl_easy_setopt(curl, CURLOPT_POST, 1L);
7517dd
+      curl_easy_setopt(curl, CURLOPT_POSTFIELDS, testput);
7517dd
+      curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(testput));
7517dd
+      res = curl_easy_perform(curl);
7517dd
+    }
7517dd
+    curl_easy_cleanup(curl);
7517dd
+  }
7517dd
+
7517dd
+  curl_global_cleanup();
7517dd
+  return (int)res;
7517dd
+}
7517dd
-- 
7517dd
2.37.3
7517dd