url: init req.no_body in DO so that it works for h2 push

req.no_body was only initialized in Curl_connect, while HTTP/2 server
push adds a duplicated handle via Curl_multi_add_perform and calls
Curl_init_do with conn==NULL, never invoking Curl_connect.

Verify it by amending test 1620

Found by Codex Security

Closes #21194
This commit is contained in:
Daniel Stenberg 2026-04-01 15:44:02 +02:00
parent 93e80c75b4
commit b27e828b93
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
2 changed files with 19 additions and 0 deletions

View file

@ -3514,6 +3514,7 @@ CURLcode Curl_init_do(struct Curl_easy *data, struct connectdata *conn)
data->state.done = FALSE; /* *_done() is not called yet */
data->req.no_body = data->set.opt_no_body;
if(data->req.no_body)
/* in HTTP lingo, no body means using the HEAD request... */
data->state.httpreq = HTTPREQ_HEAD;

View file

@ -72,6 +72,7 @@ static CURLcode test_unit1620(const char *arg)
CURLcode result;
struct Curl_easy *empty;
struct Curl_easy *dupe = NULL;
enum dupstring i;
bool connected = FALSE;
@ -95,6 +96,20 @@ static CURLcode test_unit1620(const char *arg)
result = Curl_init_do(empty, empty->conn);
fail_unless(result == CURLE_OK, "Curl_init_do() failed");
result = curl_easy_setopt((CURL *)empty, CURLOPT_NOBODY, 1L);
fail_unless(result == CURLE_OK, "curl_easy_setopt(CURLOPT_NOBODY) failed");
dupe = (struct Curl_easy *)curl_easy_duphandle((CURL *)empty);
if(!dupe)
Curl_close(&empty);
abort_unless(dupe, "curl_easy_duphandle() failed");
result = Curl_init_do(dupe, NULL);
fail_unless(result == CURLE_OK, "Curl_init_do() on duplicate failed");
fail_unless(dupe->req.no_body, "duplicate handle should keep no_body");
fail_unless(dupe->state.httpreq == HTTPREQ_HEAD,
"duplicate handle should use HTTPREQ_HEAD");
t1620_parse("hostname", "hostname", NULL, NULL);
t1620_parse("user:password", "user", "password", NULL);
t1620_parse("user:password;options", "user", "password", "options");
@ -116,6 +131,9 @@ static CURLcode test_unit1620(const char *arg)
fail_unless(empty->set.str[i] == NULL, "Curl_free() did not set to NULL");
}
result = Curl_close(&dupe);
fail_unless(result == CURLE_OK, "Curl_close() failed for duplicate");
result = Curl_close(&empty);
fail_unless(result == CURLE_OK, "Curl_close() failed");