easy: allow connect-only handle reuse with easy_perform

- Detach and disconnect an attached connection before performing.

Prior to this change it was not possible to safely reuse an easy handle
with an attached connection in a second call to curl_easy_perform. The
only known case of this is a connect-only type handle where the
connection was detached when curl_easy_perform returned, only to be
reattached by either curl_easy_send/recv.

This commit effectively reverts 2f8ecd5d and be82a360, the latter of
which treated the reuse as an error. Prior to that change undefined
behavior may occur in such a case.

Bug: https://curl.se/mail/lib-2025-01/0044.html
Reported-by: Aleksander Mazur

Closes https://github.com/curl/curl/pull/16008
This commit is contained in:
Jay Satiro 2025-01-15 03:56:11 -05:00
parent f25a807a7d
commit 4f99efb192
4 changed files with 55 additions and 23 deletions

View file

@ -7,7 +7,7 @@ HTTP GET
</info>
<reply>
<data>
<data nocheck="yes">
HTTP/1.1 200 OK swsclose
Server: test-server/fake
Last-Modified: Tue, 13 Jun 2000 12:10:00 GMT
@ -38,15 +38,33 @@ http://%HOSTIP:%HTTPPORT
#
# Verify data after the test has been "shot"
<verify>
<stdout>
HTTP/1.1 200 OK swsclose
Server: test-server/fake
Last-Modified: Tue, 13 Jun 2000 12:10:00 GMT
Content-Length: 6
Connection: close
-foo-
HTTP/1.1 200 OK swsclose
Server: test-server/fake
Last-Modified: Tue, 13 Jun 2000 12:10:00 GMT
Content-Length: 6
Connection: close
-foo-
</stdout>
<protocol>
GET /556 HTTP/1.1
Host: ninja
GET /556 HTTP/1.1
Host: ninja
</protocol>
# 43 == CURLE_BAD_FUNCTION_ARGUMENT
<errorcode>
43
0
</errorcode>
</verify>
</testcase>