]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fix BZ #338606. Basically, the bug was that it was believed that
authorFlorian Krohm <florian@eich-krohm.de>
Tue, 21 Jul 2015 21:37:23 +0000 (21:37 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Tue, 21 Jul 2015 21:37:23 +0000 (21:37 +0000)
the interpreter following the #! has to be an absolute path name.
Not so; relative path works just fine.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15429

12 files changed:
NEWS
coregrind/m_ume/script.c
none/tests/scripts/Makefile.am
none/tests/scripts/relative1 [new file with mode: 0755]
none/tests/scripts/relative1.stderr.exp [new file with mode: 0644]
none/tests/scripts/relative1.stdout.exp [new file with mode: 0644]
none/tests/scripts/relative1.vgtest [new file with mode: 0644]
none/tests/scripts/relative2 [new file with mode: 0755]
none/tests/scripts/relative2.stderr.exp [new file with mode: 0644]
none/tests/scripts/relative2.stdout.exp [new file with mode: 0644]
none/tests/scripts/relative2.vgtest [new file with mode: 0644]
none/tests/scripts/say-hello.helper [new file with mode: 0755]

diff --git a/NEWS b/NEWS
index 8d66b1159e8b30340e81b68cf88950b94db27658..b21a77e35cdb55b0eb5b2be3831ffcfa5ed078a0 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -128,6 +128,7 @@ where XXXXXX is the bug number as listed below.
         == 343175
         == 342740
 335907  segfault when running wine's ddrawex/tests/surface.c under valgrind
+338606  Strange message for scripts with invalid interpreter
 338731  ppc: Fix testuite build for toolchains not supporting -maltivec
 338995  shmat with hugepages (SHM_HUGETLB) fails with EINVAL
 339045  Getting valgrind to compile and run on OS X Yosemite (10.10)
index 5c03428da282682ba540d05df246538784770b41..6751f19a63b10e91de869ccd2c998a9f983db7a6 100644 (file)
@@ -1,3 +1,4 @@
+/* -*- mode: C; c-basic-offset: 3; -*- */
 
 /*--------------------------------------------------------------------*/
 /*--- User-mode execve() for #! scripts.            m_ume_script.c ---*/
 
 #include "priv_ume.h"
 
+/* Return true, if the first line begins with #! and contains an
+   interpreter. */
 Bool VG_(match_script)(const void *hdr, SizeT len)
 {
    const HChar* script = hdr;
    const HChar* end    = script + len;
    const HChar* interp = script + 2;
 
-   // len < 4: need '#', '!', plus at least a '/' and one more char
-   if (len < 4) return False;    
+   if (len < 2) return False;    
    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.  First, skip over any space
-   // between the #! and the start of the interpreter name
+   // Find interpreter name, which may be absolute or relative.
+   // First, skip over any space between the #! and the start of the
+   // interpreter name
    while (interp < end && (*interp == ' ' || *interp == '\t')) 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
-
-   // 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
-   // for an example.
+   // No interpreter found.
+   if (*interp == '\n') return False;
 
    return True;   // looks like a #! script
 }
@@ -103,8 +96,6 @@ Int VG_(load_script)(Int fd, const HChar* name, ExeInfo* info)
    while (interp < end && (*interp == ' ' || *interp == '\t'))
       interp++;
 
-   vg_assert(*interp == '/');   /* absolute path only for interpreter */
-
    /* skip over interpreter name */
    for (cp = interp; cp < end && !VG_(isspace)(*cp); cp++)
       ;
index ab6d0de2d81376494e95f5f927bc2b4f1de56049..8e4749d5028bad7143eb7d9caab4ad100dc1cad0 100644 (file)
@@ -7,7 +7,9 @@ dist_noinst_SCRIPTS = \
        filter_stderr
 
 EXTRA_DIST = \
+       say-hello.helper \
        bug231357.vgtest bug231357.stderr.exp bug231357.stdout.exp \
+       bug338606.vgtest bug338606.stderr.exp \
        shell shell.vgtest shell.stderr.exp shell.stderr.exp-dash \
        shell.stdout.exp shell.stderr.exp-dash2 shell.stderr.exp-illumos \
        shell.stderr.exp-solaris shell.stderr.exp-solaris-spawn \
@@ -22,6 +24,8 @@ EXTRA_DIST = \
        shell_nointerp3.stdout.exp \
        shell_nonexec.vgtest shell_nonexec.stderr.exp \
        shell_nosuchfile.vgtest shell_nosuchfile.stderr.exp \
+       relative1 relative1.vgtest relative1.stderr.exp relative1.stdout.exp \
+       relative2 relative2.vgtest relative2.stderr.exp relative2.stdout.exp \
        shell_valid1 shell_valid1.vgtest shell_valid1.stderr.exp \
        shell_valid4 shell_valid4.vgtest shell_valid4.stderr.exp \
        shell_valid4.stdout.exp \
diff --git a/none/tests/scripts/relative1 b/none/tests/scripts/relative1
new file mode 100755 (executable)
index 0000000..e08a422
--- /dev/null
@@ -0,0 +1 @@
+#!./say-hello.helper
diff --git a/none/tests/scripts/relative1.stderr.exp b/none/tests/scripts/relative1.stderr.exp
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/none/tests/scripts/relative1.stdout.exp b/none/tests/scripts/relative1.stdout.exp
new file mode 100644 (file)
index 0000000..ce01362
--- /dev/null
@@ -0,0 +1 @@
+hello
diff --git a/none/tests/scripts/relative1.vgtest b/none/tests/scripts/relative1.vgtest
new file mode 100644 (file)
index 0000000..0cb93f1
--- /dev/null
@@ -0,0 +1,2 @@
+prog: relative1
+vgopts: -q
diff --git a/none/tests/scripts/relative2 b/none/tests/scripts/relative2
new file mode 100755 (executable)
index 0000000..ad27326
--- /dev/null
@@ -0,0 +1 @@
+#!   ../scripts/./say-hello.helper  
diff --git a/none/tests/scripts/relative2.stderr.exp b/none/tests/scripts/relative2.stderr.exp
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/none/tests/scripts/relative2.stdout.exp b/none/tests/scripts/relative2.stdout.exp
new file mode 100644 (file)
index 0000000..ce01362
--- /dev/null
@@ -0,0 +1 @@
+hello
diff --git a/none/tests/scripts/relative2.vgtest b/none/tests/scripts/relative2.vgtest
new file mode 100644 (file)
index 0000000..6b0bc76
--- /dev/null
@@ -0,0 +1,2 @@
+prog: relative2
+vgopts: -q
diff --git a/none/tests/scripts/say-hello.helper b/none/tests/scripts/say-hello.helper
new file mode 100755 (executable)
index 0000000..21ba682
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+echo hello