From f5b46f133aa7af7c22eb57920d28a27ec35aa2c4 Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Wed, 10 Feb 2010 16:09:06 +0100 Subject: [PATCH] Fix SEGV if $HOME or $PWD are unset in the environment (bnc #578684) --- src/Zypper.cc | 10 +++++++--- src/utils/Augeas.cc | 7 +++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Zypper.cc b/src/Zypper.cc index b80c623..e2c52a4 100644 --- a/src/Zypper.cc +++ b/src/Zypper.cc @@ -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 } diff --git a/src/utils/Augeas.cc b/src/utils/Augeas.cc index e3580f1..f0e1c4f 100644 --- a/src/utils/Augeas.cc +++ b/src/utils/Augeas.cc @@ -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 -- 2.7.4