diff options
author | Profpatsch <mail@profpatsch.de> | 2016-04-23 17:19:19 +0200 |
---|---|---|
committer | Profpatsch <mail@profpatsch.de> | 2016-04-23 17:54:32 +0200 |
commit | 77fa336849704071d068ecc199e6fbbbb85d9546 (patch) | |
tree | 3025115eefbb151d38cb2f0c60df29b9526e0047 /pkgs/stdenv/generic | |
parent | 6d432531c61edf1aaae11b044d52d7332e522475 (diff) |
setup.hs: substitute uses only valid bash names
bash variable names may only contain alphanumeric ASCII-symbols and _, and must not start with a number. Nix expression attribute names however might contain nearly every character (in particular spaces and dashes). Previously, a substitution that was not a valid bash name would be expanded to an empty string. This commit introduce a check that throws a (hopefully) helpful error when a wrong name is used in a substitution.
Diffstat (limited to 'pkgs/stdenv/generic')
-rw-r--r-- | pkgs/stdenv/generic/setup.sh | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 9399ff7a76437..f7f9cd533c1f1 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -408,6 +408,11 @@ substitute() { if [ "$p" = --subst-var ]; then varName="${params[$((n + 1))]}" + # check if the used nix attribute name is a valid bash name + if ! [[ "$varName" =~ ^[a-zA-Z_]+[a-zA-Z0-9_]*$ ]]; then + echo "substitution variables must be valid bash names, \"$varName\" isn't." + exit 1; + fi pattern="@$varName@" replacement="${!varName}" n=$((n + 1)) @@ -439,6 +444,7 @@ substituteAll() { local output="$2" # Select all environment variables that start with a lowercase character. + # Will not work with nix attribute names (and thus env variables) containing '\n'. for envVar in $(env | sed -e $'s/^\([a-z][^=]*\)=.*/\\1/; t \n d'); do if [ "$NIX_DEBUG" = "1" ]; then echo "$envVar -> ${!envVar}" |