From 77fa336849704071d068ecc199e6fbbbb85d9546 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Sat, 23 Apr 2016 17:19:19 +0200 Subject: 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. --- pkgs/stdenv/generic/setup.sh | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'pkgs/stdenv/generic/setup.sh') diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 9399ff7a7643..f7f9cd533c1f 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}" -- cgit 1.4.1