From 34a8901eb82f9177616f4a423aa450a94a4fa2e9 Mon Sep 17 00:00:00 2001 From: Ben Gras Date: Tue, 20 Dec 2011 16:20:32 +0100 Subject: [PATCH] vfs,avfs: verify an interpreter was found on #! line . if not, NULL *interp is dereferenced --- servers/avfs/exec.c | 3 +++ servers/vfs/exec.c | 3 +++ test/run | 2 +- test/testinterp.sh | 14 ++++++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100755 test/testinterp.sh diff --git a/servers/avfs/exec.c b/servers/avfs/exec.c index 45a1b9321..5b0ac598c 100644 --- a/servers/avfs/exec.c +++ b/servers/avfs/exec.c @@ -503,6 +503,9 @@ char path[PATH_MAX]; /* path to script file */ } } + if(!interp) + return ENOEXEC; + /* Round *stk_bytes up to the size of a pointer for alignment contraints. */ *stk_bytes= ((*stk_bytes + PTRSIZE - 1) / PTRSIZE) * PTRSIZE; diff --git a/servers/vfs/exec.c b/servers/vfs/exec.c index d05fc3b37..43af7d6a2 100644 --- a/servers/vfs/exec.c +++ b/servers/vfs/exec.c @@ -444,6 +444,9 @@ vir_bytes *stk_bytes /* size of initial stack */ } } + if(!interp) + return ENOEXEC; + /* Round *stk_bytes up to the size of a pointer for alignment contraints. */ *stk_bytes= ((*stk_bytes + PTRSIZE - 1) / PTRSIZE) * PTRSIZE; diff --git a/test/run b/test/run index eed3970ca..1069c6f06 100755 --- a/test/run +++ b/test/run @@ -16,7 +16,7 @@ tests=" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \ 41 42 43 44 45 45-gcc 46 47 48 49 49-gcc 50 \ 51 51-gcc 52 52-gcc 53 54 55 56 57 58 59\ 60 61 \ - sh1.sh sh2.sh" + sh1.sh sh2.sh interp.sh" tests_no=`expr 0` # Directory must be owned by bin diff --git a/test/testinterp.sh b/test/testinterp.sh new file mode 100755 index 000000000..b00c8e0e6 --- /dev/null +++ b/test/testinterp.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +# See if the system can handle an unexpected whitespace-only interpreter line + +echo -n "Test interpreter " + +set -e +TMPSH=tst$$.sh +rm -f $TMPSH +echo '#! ' >$TMPSH +chmod 755 $TMPSH +./$TMPSH || true +rm -f $TMPSH +echo "ok" -- 2.44.0