Skip to content

Commit a255880

Browse files
authored
Merge pull request #6 from termux/check-executable-permission
Check executable permission of file (#5)
2 parents de02819 + e127449 commit a255880

File tree

4 files changed

+8
-1
lines changed

4 files changed

+8
-1
lines changed

run-tests.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ for f in tests/*.sh; do
99
ACTUAL_FILE=$f-actual
1010

1111
rm -f $ACTUAL_FILE
12-
$f myarg1 myarg2 > $ACTUAL_FILE
12+
$f myarg1 myarg2 &> $ACTUAL_FILE
1313

1414
if cmp --silent $ACTUAL_FILE $EXPECTED_FILE; then
1515
printf " OK\n"

termux-exec.c

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ int execve(const char* filename, char* const* argv, char *const envp[])
2626
char filename_buffer[512];
2727
filename = termux_rewrite_executable(filename, filename_buffer, sizeof(filename_buffer));
2828

29+
// Error out if the file is not executable:
30+
if (access(filename, X_OK) != 0) goto final;
31+
2932
fd = open(filename, O_RDONLY);
3033
if (fd == -1) goto final;
3134

tests/not-executable.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
echo hello

tests/not-executable.sh-expected

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
./run-tests.sh: line 12: tests/not-executable.sh: Permission denied

0 commit comments

Comments
 (0)