commit 7ed3ffc7ea4000096e7253fdb741f55903fd14b3 Author: snow flurry Date: Wed Jan 26 12:39:00 2022 -0800 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bdcddbf --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +.PHONY: all +all: build/parent-null build/parent-ptr build/child + +build: + @mkdir -p build + +build/parent-null: build + $(CC) -o build/parent-null src/parent.c + +build/parent-ptr: build + $(CC) -o build/parent-ptr -DPTR_TO_NULL src/parent.c + +build/child: build + $(CC) -o build/child src/child.c + +.PHONY: test +test: all + @echo "==> Testing execve with { NULL }..." + ./build/parent-ptr ./build/child + @echo "==> Testing execve with NULL..." + ./build/parent-null ./build/child + +.PHONY: clean +clean: + @rm -fr build diff --git a/README.md b/README.md new file mode 100644 index 0000000..1d95bde --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# argv0-test + +Simple tester for weird execve calls. + +## How to use +``` +$ make test +``` diff --git a/src/child.c b/src/child.c new file mode 100644 index 0000000..c0ef351 --- /dev/null +++ b/src/child.c @@ -0,0 +1,7 @@ +#include + +int +main(int argc, char *argv[]) { + printf("childproc: argc == %d!\n", argc); + return 0; +} diff --git a/src/parent.c b/src/parent.c new file mode 100644 index 0000000..a95c239 --- /dev/null +++ b/src/parent.c @@ -0,0 +1,20 @@ +#include +#include + +int +main(int argc, char **argv, char **envp) +{ + char *arr = NULL; + char **ptr = +#ifdef PTR_TO_NULL + &arr; + printf("%s: using &NULL as argv...\n", argv[0]); +#else + NULL; + printf("%s: using just NULL as argv...\n", argv[0]); +#endif + printf("%s: argv == %p\n", argv[0], ptr); + execve(argv[1], ptr, envp); + + return 0; +}