Fix SEGV if $HOME or $PWD are unset in the environment (bnc #578684)
authorMichael Andres <ma@suse.de>
Wed, 10 Feb 2010 15:09:06 +0000 (16:09 +0100)
committerMichael Andres <ma@suse.de>
Wed, 10 Feb 2010 15:09:06 +0000 (16:09 +0100)
src/Zypper.cc
src/utils/Augeas.cc

index b80c623..e2c52a4 100644 (file)
@@ -698,9 +698,13 @@ void Zypper::commandShell()
 
   string histfile;
   try {
-    Pathname p (getenv ("HOME"));
-    p /= ".zypper_history";
-    histfile = p.asString ();
+    const char * env = getenv ("HOME");
+    if ( env )
+    {
+      Pathname p( env );
+      p /= ".zypper_history";
+      histfile = p.asString ();
+    }
   } catch (...) {
     // no history
   }
index e3580f1..f0e1c4f 100644 (file)
@@ -35,7 +35,8 @@ Augeas::Augeas(const string & file)
     want_custom = true;
     if (filepath.relative())
     {
-      string wd = ::getenv("PWD");
+      const char * env = ::getenv("PWD");
+      string wd = env ? env : ".";
       filepath = wd / filepath;
     }
 
@@ -44,7 +45,9 @@ Augeas::Augeas(const string & file)
   }
   else
   {
-    _homedir = ::getenv("HOME");
+    const char * env = ::getenv("HOME");
+    if ( env )
+      _homedir = env;
     if (_homedir.empty())
       WAR << "Cannot figure out user's home directory. Skipping user's config." << endl;
     else