url: don't assume all transfers have hostnames

Follow-up from 412cd2577a

Add test 1659 to verify --connect-to when doing file:// transfers.

Reported-by: James Fuller
Closes #20948
This commit is contained in:
Daniel Stenberg 2026-03-17 09:35:31 +01:00
parent 1e3c2bec7e
commit b98981e16b
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
3 changed files with 31 additions and 4 deletions

View file

@ -2749,8 +2749,9 @@ static CURLcode parse_connect_to_string(struct Curl_easy *data,
/* check whether the URL's hostname matches. Use the URL hostname
* when it was an IPv6 address. Otherwise use the connection's hostname
* that has IDN conversion. */
char *hostname_to_match = (data->state.up.hostname[0] == '[') ?
data->state.up.hostname : conn->host.name;
char *hostname_to_match =
(data->state.up.hostname && data->state.up.hostname[0] == '[') ?
data->state.up.hostname : conn->host.name;
size_t hlen = strlen(hostname_to_match);
host_match = curl_strnequal(ptr, hostname_to_match, hlen);
ptr += hlen;

View file

@ -221,8 +221,7 @@ test1630 test1631 test1632 test1633 test1634 test1635 test1636 test1637 \
test1640 test1641 test1642 test1643 \
\
test1650 test1651 test1652 test1653 test1654 test1655 test1656 test1657 \
test1658 \
test1660 test1661 test1662 test1663 test1664 test1665 \
test1658 test1659 test1660 test1661 test1662 test1663 test1664 test1665 \
\
test1670 test1671 \
\

27
tests/data/test1659 Normal file
View file

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="US-ASCII"?>
<testcase>
<info>
<keywords>
--connect-to
FILE
</keywords>
</info>
<client>
<features>
file
</features>
<name>
--connect-to when using file:// URL
</name>
<command>
file://localhost%FILE_PWD/%LOGDIR/test%TESTNUMBER.txt --connect-to localhost:8080:localhost:8080
</command>
<file name="%LOGDIR/test%TESTNUMBER.txt">
1234567890
</file>
</client>
<verify>
</verify>
</testcase>