about summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorTaahir Ahmed <ahmed.taahir@gmail.com>2017-07-30 13:42:20 -0500
committerTaahir Ahmed <ahmed.taahir@gmail.com>2017-08-08 03:46:47 -0500
commite1d46c0c4d3bdb0aa42a04bc2bfcadc641b4ac05 (patch)
treee3f0485cbc212c2ec61b39069292661ea8a68330 /pkgs/build-support
parentba68231273bea4cba01413fd2a0e56d68db9234c (diff)
downloadnixlib-e1d46c0c4d3bdb0aa42a04bc2bfcadc641b4ac05.tar
nixlib-e1d46c0c4d3bdb0aa42a04bc2bfcadc641b4ac05.tar.gz
nixlib-e1d46c0c4d3bdb0aa42a04bc2bfcadc641b4ac05.tar.bz2
nixlib-e1d46c0c4d3bdb0aa42a04bc2bfcadc641b4ac05.tar.lz
nixlib-e1d46c0c4d3bdb0aa42a04bc2bfcadc641b4ac05.tar.xz
nixlib-e1d46c0c4d3bdb0aa42a04bc2bfcadc641b4ac05.tar.zst
nixlib-e1d46c0c4d3bdb0aa42a04bc2bfcadc641b4ac05.zip
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.
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/setup-hooks/make-wrapper.sh14
1 files changed, 14 insertions, 0 deletions
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}_"