From 2c45774a35b10659960101a73bbd5ccbfb45e4fb Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Fri, 20 Oct 2017 07:37:40 -0600 Subject: [PATCH] Treat an empty hostname as a failure and return NULL. --- lib/util/gethostname.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/util/gethostname.c b/lib/util/gethostname.c index 7f24458d6..a10243f39 100644 --- a/lib/util/gethostname.c +++ b/lib/util/gethostname.c @@ -42,7 +42,7 @@ sudo_gethostname_v1(void) hname = malloc(host_name_max + 1); if (hname != NULL) { - if (gethostname(hname, host_name_max + 1) == 0) { + if (gethostname(hname, host_name_max + 1) == 0 && *hname != '\0') { /* Old gethostname() may not NUL-terminate if there is no room. */ hname[host_name_max] = '\0'; } else { -- 2.40.0