peer: fix compare of hostname for uds

Unix domain socket paths need to be compared case-senstive, in contrast
to DNS hostnames.

Follow-up to bc40e09f63

Pointed out by Codex Security

Closes #21511
This commit is contained in:
Stefan Eissing 2026-05-06 09:24:50 +02:00 committed by Daniel Stenberg
parent 06839bda76
commit 455bebc2c7
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2

View file

@ -318,15 +318,24 @@ bool Curl_peer_equal(struct Curl_peer *p1, struct Curl_peer *p2)
Curl_peer_same_destination(p1, p2));
}
static bool peer_same_hostname(struct Curl_peer *p1, struct Curl_peer *p2)
{
/* UNIX domain socket paths must be compared case-sensitive,
* as many filesystem are like that. */
return (p1->unix_socket == p2->unix_socket) &&
(p1->abstract_uds == p2->abstract_uds) &&
(p1->ipv6 == p2->ipv6) &&
(p1->unix_socket ?
!strcmp(p1->hostname, p2->hostname) :
curl_strequal(p1->hostname, p2->hostname));
}
bool Curl_peer_same_destination(struct Curl_peer *p1, struct Curl_peer *p2)
{
return (p1 == p2) ||
(p1 && p2 &&
(p1->port == p2->port) &&
curl_strequal(p1->hostname, p2->hostname) &&
(p1->ipv6 == p2->ipv6) &&
(p1->unix_socket == p2->unix_socket) &&
(p1->abstract_uds == p2->abstract_uds) &&
peer_same_hostname(p1, p2) &&
(p1->scopeid == p2->scopeid) &&
(p1->scopeid || curl_strequal(p1->zoneid, p2->zoneid)));
}