aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornjn <njn@a5019735-40e9-0310-863c-91ae7b9d1cf9>2009-06-29 06:57:30 +0000
committernjn <njn@a5019735-40e9-0310-863c-91ae7b9d1cf9>2009-06-29 06:57:30 +0000
commit33e57a7bcf079398e9003f892a853037f9bd5de0 (patch)
tree29f9b99acc7c8d09afda7c278a40ef6da7f08c2e
parent2c4e5358db11e4d69efb7d9c3ef2baa4a87af220 (diff)
downloadvalgrind-33e57a7bcf079398e9003f892a853037f9bd5de0.tar.gz
Make the Linux launcher more like the Darwin one in how it reads the
executable headers. This means it no longer crashes on an empty executable. Fixes bug 156065. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@10384 a5019735-40e9-0310-863c-91ae7b9d1cf9
-rw-r--r--coregrind/launcher-linux.c11
-rw-r--r--none/tests/empty-exe.stderr.exp2
-rw-r--r--none/tests/empty-exe.vgtest9
3 files changed, 17 insertions, 5 deletions
diff --git a/coregrind/launcher-linux.c b/coregrind/launcher-linux.c
index 1713434e5..34754d02a 100644
--- a/coregrind/launcher-linux.c
+++ b/coregrind/launcher-linux.c
@@ -112,7 +112,8 @@ static const char *find_client(const char *clientname)
static const char *select_platform(const char *clientname)
{
int fd;
- unsigned char *header;
+ uint8_t header[4096];
+ ssize_t bytes;
const char *platform = NULL;
long pagesize = sysconf(_SC_PAGESIZE);
@@ -123,11 +124,11 @@ static const char *select_platform(const char *clientname)
return NULL;
// barf("open(%s): %s", clientname, strerror(errno));
- if ((header = mmap(NULL, pagesize, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0)) == MAP_FAILED)
- return NULL;
- // barf("mmap(%s): %s", clientname, strerror(errno));
-
+ bytes = read(fd, header, sizeof(header));
close(fd);
+ if (bytes != sizeof(header)) {
+ return NULL;
+ }
if (header[0] == '#' && header[1] == '!') {
char *interp = (char *)header + 2;
diff --git a/none/tests/empty-exe.stderr.exp b/none/tests/empty-exe.stderr.exp
new file mode 100644
index 000000000..139597f9c
--- /dev/null
+++ b/none/tests/empty-exe.stderr.exp
@@ -0,0 +1,2 @@
+
+
diff --git a/none/tests/empty-exe.vgtest b/none/tests/empty-exe.vgtest
new file mode 100644
index 000000000..71fef2eda
--- /dev/null
+++ b/none/tests/empty-exe.vgtest
@@ -0,0 +1,9 @@
+# Bug 162020: running an empty executable used to crash Valgrind. Note that
+# the (old) crash message gets filtered out, so it's the presence of the
+# blank two lines in the .stderr.exp file that are important -- they
+# indicate it ran to completion. If the crash occurs, the .stderr.out file
+# is empty.
+prereq: touch empty-exe && chmod u+x empty-exe
+prog: empty-exe
+vgopts:
+cleanup: rm -f empty-exe