]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
easy: make curl_easy_perform() return error if connection still there
authorDaniel Stenberg <daniel@haxx.se>
Tue, 14 Jan 2025 14:47:21 +0000 (15:47 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 14 Jan 2025 15:32:46 +0000 (16:32 +0100)
This typically happens if CURL_CONNECT_ONLY is used and a second
curl_easy_perform() is attempted.

A connection "taken over" with CURL_CONNECT_ONLY cannot be ended any
other way than a curl_easy_cleanup() on the easy handle that holds it.

Add test 696 to verify.

Closes #16003

lib/easy.c
tests/data/Makefile.am
tests/data/test696 [new file with mode: 0644]
tests/libtest/Makefile.inc
tests/libtest/lib556.c

index 87cb9867d3b9abd62f454509ffdda884e27ebfef..657e007a94bb5f4a1ac4ce10a969a0e86ffc9613 100644 (file)
@@ -751,6 +751,11 @@ static CURLcode easy_perform(struct Curl_easy *data, bool events)
   if(!data)
     return CURLE_BAD_FUNCTION_ARGUMENT;
 
+  if(data->conn) {
+    failf(data, "cannot use again while associated with a connection");
+    return CURLE_BAD_FUNCTION_ARGUMENT;
+  }
+
   if(data->set.errorbuffer)
     /* clear this as early as possible */
     data->set.errorbuffer[0] = 0;
index a68d3d9114b97ecf4a5011efc9490e0aa1bd1c0b..f39a30f466c4093989319dd51d64decadc500a9d 100644 (file)
@@ -101,7 +101,7 @@ test652 test653 test654 test655 test656 test658 test659 test660 test661 \
 test662 test663 test664 test665 test666 test667 test668 test669 test670 \
 test671 test672 test673 test674 test675 test676 test677 test678 test679 \
 test680 test681 test682 test683 test684 test685 test686 test687 test688 \
-test689 test690 test691 test692 test693 test694 test695 \
+test689 test690 test691 test692 test693 test694 test695 test696 \
 \
 test700 test701 test702 test703 test704 test705 test706 test707 test708 \
 test709 test710 test711 test712 test713 test714 test715 test716 test717 \
diff --git a/tests/data/test696 b/tests/data/test696
new file mode 100644 (file)
index 0000000..8b0bfd4
--- /dev/null
@@ -0,0 +1,52 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+</keywords>
+</info>
+
+<reply>
+<data>
+HTTP/1.1 200 OK swsclose\r
+Server: test-server/fake\r
+Last-Modified: Tue, 13 Jun 2000 12:10:00 GMT\r
+Content-Length: 6\r
+Connection: close\r
+\r
+-foo-
+</data>
+</reply>
+
+#
+# Client-side
+<client>
+<server>
+http
+</server>
+<tool>
+lib%TESTNUMBER
+</tool>
+<name>
+CONNECT_ONLY and doing a second curl_easy_perform
+</name>
+<command>
+http://%HOSTIP:%HTTPPORT
+</command>
+</client>
+
+#
+# Verify data after the test has been "shot"
+<verify>
+<protocol>
+GET /556 HTTP/1.1\r
+Host: ninja\r
+\r
+</protocol>
+
+# 43 == CURLE_BAD_FUNCTION_ARGUMENT
+<errorcode>
+43
+</errorcode>
+</verify>
+</testcase>
index ba0aa9ca95ee959d0a2d3186282b98ad8f4a9a71..d0acf63778b696d3f3b399ebddf39450cee533c2 100644 (file)
@@ -49,6 +49,7 @@ LIBTESTPROGS = libauthretry libntlmconnect libprereq                     \
  lib643        lib645 lib650 lib651 lib652 lib653 lib654 lib655 lib658   \
  lib659 lib661 lib666 lib667 lib668 \
  lib670 lib671 lib672 lib673 lib674 lib676 lib677 lib678 lib694 lib695   \
+ lib696 \
  lib1156 \
  lib1301 \
  lib1485 \
@@ -342,6 +343,9 @@ lib694_SOURCES = lib694.c $(SUPPORTFILES)
 
 lib695_SOURCES = lib695.c $(SUPPORTFILES)
 
+lib696_SOURCES = lib556.c $(SUPPORTFILES)
+lib696_CPPFLAGS = $(AM_CPPFLAGS) -DLIB696
+
 lib1301_SOURCES = lib1301.c $(SUPPORTFILES) $(TESTUTIL)
 lib1301_LDADD = $(TESTUTIL_LIBS)
 
index 06532c6161d9c761fc15d9a806630320b63d9090..36f845ff7a40fdd765010aaa49ea38ae7642d314 100644 (file)
@@ -97,6 +97,15 @@ CURLcode test(char *URL)
       res = TEST_ERR_FAILURE;
   }
 
+#ifdef LIB696
+  /* attempt to use the handle again */
+  test_setopt(curl, CURLOPT_URL, URL);
+  test_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
+  test_setopt(curl, CURLOPT_VERBOSE, 1L);
+
+  res = curl_easy_perform(curl);
+#endif
+
 test_cleanup:
 
   curl_easy_cleanup(curl);