From 9a2482557dcc22736bdd6c0472903ca0a6e7e4e5 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Fri, 17 Sep 2021 11:17:15 -0700 Subject: [PATCH] get_hostname_identifier to not return empty hostnames When getting the hostname to construct the legacy uvar path, if the hostname is empty, we will create a path pointing at a directory. On BSDs this path can be successfully open'd and we will produce errors about invalid uvar files. --- src/env_universal_common.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/env_universal_common.cpp b/src/env_universal_common.cpp index 29f200a87..800f2ea2e 100644 --- a/src/env_universal_common.cpp +++ b/src/env_universal_common.cpp @@ -981,7 +981,8 @@ bool get_hostname_identifier(wcstring &result) { if (gethostname(hostname, sizeof(hostname)) == 0) { result.assign(str2wcstring(hostname)); result.assign(truncate(result, HOSTNAME_LEN)); - success = true; + // Don't return an empty hostname, we may attempt to open a directory instead. + success = !result.empty(); } return success; }