From e1d46c0c4d3bdb0aa42a04bc2bfcadc641b4ac05 Mon Sep 17 00:00:00 2001 From: Taahir Ahmed Date: Sun, 30 Jul 2017 13:42:20 -0500 Subject: makeWrapper: Only wrap normal executable files `makeWrapper` and `wrapProgram` are being invoked on all kinds of wacky things (usually with the help of bash globs or other machine assistance). So far, I have come across `wrapProgram` being invoked on a directory, as well as on the empty string. As far as I can tell, it's only valid to invoke these utilities on a normal (non-directory, non-device) executable file. This commit enforces that precondition. --- pkgs/build-support/setup-hooks/make-wrapper.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'pkgs/build-support') diff --git a/pkgs/build-support/setup-hooks/make-wrapper.sh b/pkgs/build-support/setup-hooks/make-wrapper.sh index eebde886a884..5429bc41272a 100644 --- a/pkgs/build-support/setup-hooks/make-wrapper.sh +++ b/pkgs/build-support/setup-hooks/make-wrapper.sh @@ -1,3 +1,12 @@ +# Assert that FILE exists and is executable +# +# assertExecutable FILE +assertExecutable() { + local file="$1" + [[ -f "${file}" && -x "${file}" ]] || \ + die "Cannot wrap ${file} because it is not an executable file" +} + # construct an executable file that wraps the actual executable # makeWrapper EXECUTABLE ARGS @@ -24,6 +33,8 @@ makeWrapper() { local params varName value command separator n fileNames local argv0 flagsBefore flags + assertExecutable "${file}" + mkdir -p "$(dirname "$wrapper")" echo "#! $SHELL -e" > "$wrapper" @@ -131,6 +142,9 @@ filterExisting() { wrapProgram() { local prog="$1" local hidden + + assertExecutable "${prog}" + hidden="$(dirname "$prog")/.$(basename "$prog")"-wrapped while [ -e "$hidden" ]; do hidden="${hidden}_" -- cgit 1.4.1