forked from termux/termux-exec
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply realpath(3) when hooking readlink("/proc/self/exe")
- Loading branch information
Showing
7 changed files
with
68 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ test-binary | |
tests/fexecve | ||
tests/popen | ||
tests/system-uname | ||
tests/readlink-proc-self-exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
#include <stdio.h> | ||
|
||
int main() { | ||
FILE* file = popen("uname", "r"); | ||
char buffer[101]; | ||
fscanf(file, "%100s", buffer); | ||
pclose(file); | ||
printf("%s\n", buffer); | ||
return 0; | ||
FILE *file = popen("uname", "r"); | ||
char buffer[101]; | ||
fscanf(file, "%100s", buffer); | ||
pclose(file); | ||
printf("%s\n", buffer); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#define _DEFAULT_SOURCE | ||
#include <linux/limits.h> | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
|
||
int main() { | ||
char buf[PATH_MAX + 1]; | ||
|
||
ssize_t res = readlink("/proc/self/exe", buf, PATH_MAX); | ||
if (res < 0) { | ||
perror("readlink()"); | ||
return 1; | ||
} | ||
buf[res] = 0; | ||
printf("%s\n", buf); | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
TMPDIR=$(mktemp -d) | ||
|
||
cp tests/readlink-proc-self-exe $TMPDIR | ||
|
||
cd $TMPDIR | ||
|
||
ACTUAL_PATH_TO_SELF=$(./readlink-proc-self-exe) | ||
EXPECTED_PATH_TO_SELF=$TMPDIR/readlink-proc-self-exe | ||
|
||
if [ "$ACTUAL_PATH_TO_SELF" != "$EXPECTED_PATH_TO_SELF" ]; then | ||
echo "ERROR(1): Expected '$EXPECTED_PATH_TO_SELF', was '$ACTUAL_PATH_TO_SELF'" | ||
exit 1 | ||
fi | ||
|
||
ln -s readlink-proc-self-exe symlinked-binary | ||
ACTUAL_PATH_TO_SELF=$(./symlinked-binary) | ||
if [ "$ACTUAL_PATH_TO_SELF" != "$EXPECTED_PATH_TO_SELF" ]; then | ||
echo "ERROR(2): Expected '$EXPECTED_PATH_TO_SELF', was '$ACTUAL_PATH_TO_SELF'" | ||
exit 1 | ||
fi | ||
|
||
ln -s symlinked-binary nested-symlinked-binary | ||
ACTUAL_PATH_TO_SELF=$(./nested-symlinked-binary) | ||
if [ "$ACTUAL_PATH_TO_SELF" != "$EXPECTED_PATH_TO_SELF" ]; then | ||
echo "ERROR(3): Expected '$EXPECTED_PATH_TO_SELF', was '$ACTUAL_PATH_TO_SELF'" | ||
exit 1 | ||
fi | ||
|
||
cd - > /dev/null | ||
|
||
rm -rf $TMPDIR | ||
|
||
echo ok |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ok |