uri: hostname_is_localhost(): don’t crash if hostname == NULL

This commit is contained in:
Daniel Eklöf 2021-06-19 15:56:39 +02:00
parent 078f790b72
commit 1a755d0da2
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 5 additions and 3 deletions

View file

@ -186,6 +186,7 @@
_compose_ definitions.
* Window title not being updated while window is hidden
(https://codeberg.org/dnkl/foot/issues/591).
* Crash on badly formatted URIs in e.g. OSC-8 URLs.
### Security

7
uri.c
View file

@ -270,7 +270,8 @@ hostname_is_localhost(const char *hostname)
if (gethostname(this_host, sizeof(this_host)) < 0)
this_host[0] = '\0';
return (strcmp(hostname, "") == 0 ||
strcmp(hostname, "localhost") == 0 ||
strcmp(hostname, this_host) == 0);
return (hostname != NULL && (
strcmp(hostname, "") == 0 ||
strcmp(hostname, "localhost") == 0 ||
strcmp(hostname, this_host) == 0));
}