From 1a755d0da2075ba0cccaaacd616f31eec697b08a Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 19 Jun 2021 15:56:39 +0200 Subject: uri: hostname_is_localhost(): don’t crash if hostname == NULL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + uri.c | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ea8eec3..0fb4c8e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/uri.c b/uri.c index 51cd8093..e747991d 100644 --- a/uri.c +++ b/uri.c @@ -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)); } -- cgit v1.3