Bug 20927 - Segfault when $HOME is not set
authorDodji Seketeli <dodji@redhat.com>
Mon, 5 Dec 2016 09:11:19 +0000 (10:11 +0100)
committerDodji Seketeli <dodji@redhat.com>
Mon, 5 Dec 2016 09:21:13 +0000 (10:21 +0100)
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 <dodji@redhat.com>
src/abg-tools-utils.cc
tools/abipkgdiff.cc

index defc72e3fffdc5f4e0ff13d307d746abdcd6736f..d68fe06c9e5359602d3c5ed8700b69190dac1396 100644 (file)
@@ -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 = "~";
index 6542c32f50892357b05f7e27771789687e776045..099914172d11a19f45b7f484351f1a3eea855fcb 100644 (file)
@@ -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";
         }