From d0ea4b0d6c9ccc3e71e058a2cc4f099c074b10b2 Mon Sep 17 00:00:00 2001 From: Stas Degteff Date: Thu, 17 Feb 2011 22:05:27 +0000 Subject: [PATCH] Additional checks in strschg_environ --- goldlib/gall/gfilutl2.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/goldlib/gall/gfilutl2.cpp b/goldlib/gall/gfilutl2.cpp index 60e6526..a4adcd5 100644 --- a/goldlib/gall/gfilutl2.cpp +++ b/goldlib/gall/gfilutl2.cpp @@ -113,21 +113,23 @@ int strschg_environ(std::string& s) { int replaced = 0; size_t posn, posn1; - while(((posn=s.find('%')) != s.npos) and ((posn1=s.find('%', posn+1)) != s.npos)) { - fnd = s.substr(posn+1, posn1-1-posn); - const char* rep = getenv(fnd.c_str()); - rep = rep ? rep : ""; - s.replace(posn, posn1-posn+1, rep); - replaced++; + if (s.length() > 1) { + while(((posn=s.find('%')) != s.npos) and ((posn1=s.find('%', posn+1)) != s.npos)) { + fnd = s.substr(posn+1, posn1-1-posn); + const char* rep = getenv(fnd.c_str()); + rep = rep ? rep : ""; + s.replace(posn, posn1-posn+1, rep); + replaced++; + } + fnd.clear(); } - fnd.clear(); #ifndef __HAVE_DRIVES__ if( s[0] == '~' ) { struct passwd *pe=NULL; - size_t slash; + size_t slash = 1; - if( (s.length() > 2) and not isslash(s[1]) ) { + if( (s.length() > 1) and not isslash(s[1]) ) { slash = s.find_first_of(GOLD_SLASH_STR GOLD_WRONG_SLASH_STR, 1); std::string name(s,1,slash-1); pe = getpwnam(name.c_str()); @@ -139,6 +141,7 @@ int strschg_environ(std::string& s) { if ( slash != std::string::npos ) dirname += s.substr(slash); s=dirname; + replaced++; } } #endif