Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid shelling *nix commands #2706

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Q1 = $(V:1=)
Q = $(Q1:0=@)
ECHO1 = $(V:1=@ :)
ECHO = $(ECHO1:0=@ echo)
FUZZ_OUTPUT_DIR = $(shell pwd)/fuzz/output
FUZZ_OUTPUT_DIR = $(CURDIR)/fuzz/output
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CURDIR is technically different from shell pwd in that the latter isn’t stuck constant if the Makefile somehow cds halfway in the script.
That said, do we really want the build to base on the working directory rather than fixed at the repo root?


SOEXT := $(shell ruby -e 'puts RbConfig::CONFIG["SOEXT"]')

Expand All @@ -15,8 +15,8 @@ CFLAGS := -g -O2 -std=c99 -Wall -Werror -Wextra -Wpedantic -Wundef -Wconversion
CC := cc
WASI_SDK_PATH := /opt/wasi-sdk

HEADERS := $(shell find include -name '*.h')
SOURCES := $(shell find src -name '*.c')
HEADERS := $(wildcard include/*.h include/*/*.h include/*/*/*.h')
SOURCES := $(wildcard src/*.c src/*/*.c)
Comment on lines +18 to +19
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makefile doesn’t support recursive wildcard, so shelling out was accustomed.
The alternative is to write a custom function.

I’m fine with abandoning this change if it’s not worth to not shell-out.

For reference, mkmf-generated Makefiles does not expand recursively; that is, mkmf does not support source code subfolders.

SHARED_OBJECTS := $(subst src/,build/shared/,$(SOURCES:.c=.o))
STATIC_OBJECTS := $(subst src/,build/static/,$(SOURCES:.c=.o))

Expand Down Expand Up @@ -66,7 +66,7 @@ build/fuzz.heisenbug.%: $(SOURCES) fuzz/%.c fuzz/heisenbug.c

fuzz-debug:
$(ECHO) "entering debug shell"
$(Q) docker run -it --rm -e HISTFILE=/prism/fuzz/output/.bash_history -v $(shell pwd):/prism -v $(FUZZ_OUTPUT_DIR):/fuzz_output prism/fuzz
$(Q) docker run -it --rm -e HISTFILE=/prism/fuzz/output/.bash_history -v $(CURDIR):/prism -v $(FUZZ_OUTPUT_DIR):/fuzz_output prism/fuzz

fuzz-docker-build: fuzz/docker/Dockerfile
$(ECHO) "building docker image"
Expand All @@ -76,10 +76,10 @@ fuzz-run-%: FORCE fuzz-docker-build
$(ECHO) "generating templates"
$(Q) bundle exec rake templates
$(ECHO) "running $* fuzzer"
$(Q) docker run --rm -v $(shell pwd):/prism prism/fuzz /bin/bash -c "FUZZ_FLAGS=\"$(FUZZ_FLAGS)\" make build/fuzz.$*"
$(Q) docker run --rm -v $(CURDIR):/prism prism/fuzz /bin/bash -c "FUZZ_FLAGS=\"$(FUZZ_FLAGS)\" make build/fuzz.$*"
$(ECHO) "starting AFL++ run"
$(Q) mkdir -p $(FUZZ_OUTPUT_DIR)/$*
$(Q) docker run -it --rm -v $(shell pwd):/prism -v $(FUZZ_OUTPUT_DIR):/fuzz_output prism/fuzz /bin/bash -c "./fuzz/$*.sh /fuzz_output/$*"
$(Q) docker run -it --rm -v $(CURDIR):/prism -v $(FUZZ_OUTPUT_DIR):/fuzz_output prism/fuzz /bin/bash -c "./fuzz/$*.sh /fuzz_output/$*"
FORCE:

fuzz-clean:
Expand Down
Loading