lib: add asserts that hostname has content

For all network related protocols there must be a non-blank hostname
used. This change adds a few asserts in some places to make debug/tests
catch mistakes if any such would slip in.

Closes #19146
This commit is contained in:
Daniel Stenberg 2025-10-19 16:40:11 +02:00
parent 55e0526566
commit 7f19fa9819
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
3 changed files with 6 additions and 1 deletions

View file

@ -858,6 +858,7 @@ CURLcode Curl_resolv(struct Curl_easy *data,
/* We should intentionally error and not resolve .onion TLDs */
hostname_len = strlen(hostname);
DEBUGASSERT(hostname_len);
if(hostname_len >= 7 &&
(curl_strequal(&hostname[hostname_len - 6], ".onion") ||
curl_strequal(&hostname[hostname_len - 7], ".onion."))) {
@ -982,7 +983,7 @@ CURLcode Curl_resolv_blocking(struct Curl_easy *data,
struct Curl_dns_entry **dnsentry)
{
CURLcode result;
DEBUGASSERT(hostname && *hostname);
*dnsentry = NULL;
result = Curl_resolv(data, hostname, port, ip_version, FALSE, dnsentry);
switch(result) {
@ -1060,6 +1061,7 @@ CURLcode Curl_resolv_timeout(struct Curl_easy *data,
#endif /* USE_ALARM_TIMEOUT */
CURLcode result;
DEBUGASSERT(hostname && *hostname);
*entry = NULL;
if(timeoutms < 0)