From e127449a989f358c6ebec79ab7469c69d6949129 Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Thu, 28 Sep 2017 23:55:58 +0200 Subject: [PATCH] Check executable permission of file (#5) --- run-tests.sh | 2 +- termux-exec.c | 3 +++ tests/not-executable.sh | 3 +++ tests/not-executable.sh-expected | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 tests/not-executable.sh create mode 100644 tests/not-executable.sh-expected diff --git a/run-tests.sh b/run-tests.sh index 6720343..0c831d7 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -9,7 +9,7 @@ for f in tests/*.sh; do ACTUAL_FILE=$f-actual rm -f $ACTUAL_FILE - $f myarg1 myarg2 > $ACTUAL_FILE + $f myarg1 myarg2 &> $ACTUAL_FILE if cmp --silent $ACTUAL_FILE $EXPECTED_FILE; then printf " OK\n" diff --git a/termux-exec.c b/termux-exec.c index 66e9622..51fcb22 100644 --- a/termux-exec.c +++ b/termux-exec.c @@ -26,6 +26,9 @@ int execve(const char* filename, char* const* argv, char *const envp[]) char filename_buffer[512]; filename = termux_rewrite_executable(filename, filename_buffer, sizeof(filename_buffer)); + // Error out if the file is not executable: + if (access(filename, X_OK) != 0) goto final; + fd = open(filename, O_RDONLY); if (fd == -1) goto final; diff --git a/tests/not-executable.sh b/tests/not-executable.sh new file mode 100644 index 0000000..2a22daa --- /dev/null +++ b/tests/not-executable.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +echo hello diff --git a/tests/not-executable.sh-expected b/tests/not-executable.sh-expected new file mode 100644 index 0000000..5e7557b --- /dev/null +++ b/tests/not-executable.sh-expected @@ -0,0 +1 @@ +./run-tests.sh: line 12: tests/not-executable.sh: Permission denied