Initial commit

This commit is contained in:
snow flurry 2022-01-26 12:39:00 -08:00
commit 7ed3ffc7ea
5 changed files with 61 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
build/

25
Makefile Normal file
View file

@ -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

8
README.md Normal file
View file

@ -0,0 +1,8 @@
# argv0-test
Simple tester for weird execve calls.
## How to use
```
$ make test
```

7
src/child.c Normal file
View file

@ -0,0 +1,7 @@
#include <stdio.h>
int
main(int argc, char *argv[]) {
printf("childproc: argc == %d!\n", argc);
return 0;
}

20
src/parent.c Normal file
View file

@ -0,0 +1,20 @@
#include <stdio.h>
#include <unistd.h>
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;
}