From: Florian Krohm Date: Tue, 21 Jul 2015 21:37:23 +0000 (+0000) Subject: Fix BZ #338606. Basically, the bug was that it was believed that X-Git-Tag: svn/VALGRIND_3_11_0~218 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=128fe0d9c429a4177a165e7f69477aafab0e8149;p=thirdparty%2Fvalgrind.git Fix BZ #338606. Basically, the bug was that it was believed that 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 --- diff --git a/NEWS b/NEWS index 8d66b1159e..b21a77e35c 100644 --- 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) diff --git a/coregrind/m_ume/script.c b/coregrind/m_ume/script.c index 5c03428da2..6751f19a63 100644 --- a/coregrind/m_ume/script.c +++ b/coregrind/m_ume/script.c @@ -1,3 +1,4 @@ +/* -*- mode: C; c-basic-offset: 3; -*- */ /*--------------------------------------------------------------------*/ /*--- User-mode execve() for #! scripts. m_ume_script.c ---*/ @@ -41,35 +42,27 @@ #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++) ; diff --git a/none/tests/scripts/Makefile.am b/none/tests/scripts/Makefile.am index ab6d0de2d8..8e4749d502 100644 --- a/none/tests/scripts/Makefile.am +++ b/none/tests/scripts/Makefile.am @@ -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 index 0000000000..e08a4228f1 --- /dev/null +++ b/none/tests/scripts/relative1 @@ -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 index 0000000000..e69de29bb2 diff --git a/none/tests/scripts/relative1.stdout.exp b/none/tests/scripts/relative1.stdout.exp new file mode 100644 index 0000000000..ce01362503 --- /dev/null +++ b/none/tests/scripts/relative1.stdout.exp @@ -0,0 +1 @@ +hello diff --git a/none/tests/scripts/relative1.vgtest b/none/tests/scripts/relative1.vgtest new file mode 100644 index 0000000000..0cb93f1c44 --- /dev/null +++ b/none/tests/scripts/relative1.vgtest @@ -0,0 +1,2 @@ +prog: relative1 +vgopts: -q diff --git a/none/tests/scripts/relative2 b/none/tests/scripts/relative2 new file mode 100755 index 0000000000..ad2732666f --- /dev/null +++ b/none/tests/scripts/relative2 @@ -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 index 0000000000..e69de29bb2 diff --git a/none/tests/scripts/relative2.stdout.exp b/none/tests/scripts/relative2.stdout.exp new file mode 100644 index 0000000000..ce01362503 --- /dev/null +++ b/none/tests/scripts/relative2.stdout.exp @@ -0,0 +1 @@ +hello diff --git a/none/tests/scripts/relative2.vgtest b/none/tests/scripts/relative2.vgtest new file mode 100644 index 0000000000..6b0bc764e6 --- /dev/null +++ b/none/tests/scripts/relative2.vgtest @@ -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 index 0000000000..21ba682558 --- /dev/null +++ b/none/tests/scripts/say-hello.helper @@ -0,0 +1,2 @@ +#!/bin/sh +echo hello