]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
match_script: redo somewhat dubious (although not obviously wrong)
authorJulian Seward <jseward@acm.org>
Wed, 5 Jul 2006 22:54:49 +0000 (22:54 +0000)
committerJulian Seward <jseward@acm.org>
Wed, 5 Jul 2006 22:54:49 +0000 (22:54 +0000)
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

coregrind/m_ume.c

index 98bbe57fdee20761f2509eaec0c774ad27e17673..e46a354f9223f9e4014f94c1fd278a244d4acdfa 100644 (file)
@@ -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 */