From c6a69ae36bdfed8b274f1a608de11f0c0445407a Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Tue, 23 Feb 2021 08:25:15 -0800 Subject: [PATCH] Fixed crash on startup when running in an environment that doesn't have /home/heinzi set (e.g. an empty env), https://github.com/cryfs/cryfs/issues/374 --- ChangeLog.txt | 1 + src/cpp-utils/system/homedir.cpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 8b2e8606..d00e9642 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -5,6 +5,7 @@ Fixed bugs: * Fixed determining the user's homedir: If $HOME and the /etc/passwd entry for the current user contradict each other, now $HOME takes preference over /etc/passwd. * Fix Android compilation, https://github.com/cryfs/cryfs/issues/345 * Remove cryfs-stats tool which isn't ready yet and could destroy the file system +* Fixed crash on startup when running in an environment that doesn't have $HOME set (e.g. an empty env), https://github.com/cryfs/cryfs/issues/374 Version 0.10.2 diff --git a/src/cpp-utils/system/homedir.cpp b/src/cpp-utils/system/homedir.cpp index 4b64090d..07b670a5 100644 --- a/src/cpp-utils/system/homedir.cpp +++ b/src/cpp-utils/system/homedir.cpp @@ -9,7 +9,8 @@ using std::string; #include namespace { bf::path _get_home_directory() { - string homedir = getenv("HOME"); + const char* homedir_ = getenv("HOME"); + string homedir = (homedir_ == nullptr) ? "" : homedir_; if (homedir == "") { // try the /etc/passwd entry struct passwd* pwd = getpwuid(getuid());