From 985397a47a098dbc624d01dd79e67d2b9ebd3d4c Mon Sep 17 00:00:00 2001 From: Dodji Seketeli Date: Mon, 5 Dec 2016 10:11:19 +0100 Subject: [PATCH] Bug 20927 - Segfault when $HOME is not set When comparing two binaries with abi{pkg}diff, if $HOME is not set, we segfault at some places because we don't expect that. I ran "make check" after doing "unset HOME" to help me catch most of those places. This patch updates the code to handle that case. * src/abg-tools-utils.cc (get_default_user_suppression_file_path): Handle the case where the HOME environment variable is not set. * tools/abipkgdiff.cc (package::extracted_packages_parent_dir): Likewise. When $HOME is empty set then use $TMPDIR. If it's empty too then use "/tmp". Signed-off-by: Dodji Seketeli --- src/abg-tools-utils.cc | 2 ++ tools/abipkgdiff.cc | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/abg-tools-utils.cc b/src/abg-tools-utils.cc index defc72e3..d68fe06c 100644 --- a/src/abg-tools-utils.cc +++ b/src/abg-tools-utils.cc @@ -919,6 +919,8 @@ get_default_user_suppression_file_path() if (s == NULL) { s = getenv("HOME"); + if (s == NULL) + return ""; default_user_suppr_path = s; if (default_user_suppr_path.empty()) default_user_suppr_path = "~"; diff --git a/tools/abipkgdiff.cc b/tools/abipkgdiff.cc index 6542c32f..09991417 100644 --- a/tools/abipkgdiff.cc +++ b/tools/abipkgdiff.cc @@ -562,9 +562,17 @@ package::extracted_packages_parent_dir() p = cachedir; else { - p = getenv("HOME"); + const char* s = getenv("HOME"); + if (s != NULL) + p = s; if (p.empty()) - p = "~"; + { + s = getenv("TMPDIR"); + if (s != NULL) + p = s; + else + p = "/tmp"; + } p += "/.cache/libabigail"; } -- 2.34.1