From: Julian Seward Date: Wed, 5 Jul 2006 22:54:49 +0000 (+0000) Subject: match_script: redo somewhat dubious (although not obviously wrong) X-Git-Tag: svn/VALGRIND_3_3_0~728 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f9c5b0b2ee10d3e0794f5b2c4e3bb7f0fe168762;p=thirdparty%2Fvalgrind.git match_script: redo somewhat dubious (although not obviously wrong) logic. load_script: fix bug causing incorrect identification of script arg in the case where there is whitespace after the script name. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@5981 --- diff --git a/coregrind/m_ume.c b/coregrind/m_ume.c index 98bbe57fde..e46a354f92 100644 --- a/coregrind/m_ume.c +++ b/coregrind/m_ume.c @@ -529,10 +529,20 @@ static Bool match_script(char *hdr, Int len) if (0 != VG_(memcmp)(hdr, "#!", 2)) return False; // Find interpreter name, make sure it's an absolute path (starts with - // '/') and has at least one more char. + // '/') and has at least one more char. First, skip over any space + // between the #! and the start of the interpreter name while (interp < end && VG_(isspace)(*interp)) interp++; + + // overrun? + if (interp >= end) return False; // can't find start of interp name + + // interp should now point at the / if (*interp != '/') return False; // absolute path only for interpreter - if (interp == end) return False; // nothing after the '/' + + // check for something plausible after the / + interp++; + if (interp >= end) return False; + if (VG_(isspace)(*interp)) return False; // Here we should get the full interpreter name and check it with // check_executable(). See the "EXEC FAILED" failure when running shell @@ -584,7 +594,7 @@ static Int load_script(Int fd, const HChar* name, ExeInfo* info) if (!eol && cp < end) { /* skip space before arg */ - while (cp < end && VG_(isspace)(*cp)) + while (cp < end && VG_(isspace)(*cp) && *cp != '\n') cp++; /* arg is from here to eol */