Skip to content

Commit c4bd536

Browse files
authored
Add unset of environment variables (conda#1082)
* Add news * Add unset of environment variables * Verify expected environment variables are unset * Unset env vars also for pkg installers * Fix typo with OR instead of AND * Fix formatting * Remove uses of OLD_LD_LIBRARY_PATH * Add suggestion to news
1 parent 99e6cef commit c4bd536

File tree

5 files changed

+54
-6
lines changed

5 files changed

+54
-6
lines changed

constructor/header.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
set -eu
1111

1212
{%- if osx %}
13-
unset DYLD_LIBRARY_PATH DYLD_FALLBACK_LIBRARY_PATH
13+
unset DYLD_LIBRARY_PATH DYLD_FALLBACK_LIBRARY_PATH DYLD_INSERT_LIBRARIES DYLD_FRAMEWORK_PATH
1414
{%- else %}
15-
export OLD_LD_LIBRARY_PATH="${LD_LIBRARY_PATH:-}"
16-
unset LD_LIBRARY_PATH
15+
unset LD_LIBRARY_PATH LD_PRELOAD LD_AUDIT
1716
{%- endif %}
1817

1918
if ! echo "$0" | grep '\.sh$' > /dev/null; then

constructor/osx/run_installation.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ logger -p "install.info" "$1" || echo "$1"
2020

2121
{%- set channels = final_channels|join(",") %}
2222

23-
unset DYLD_LIBRARY_PATH
23+
unset DYLD_LIBRARY_PATH DYLD_FALLBACK_LIBRARY_PATH DYLD_INSERT_LIBRARIES DYLD_FRAMEWORK_PATH
2424

2525
PREFIX="$2/{{ pkg_name_lower }}"
2626
PREFIX=$(cd "$PREFIX"; pwd)

examples/grin/hello.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ set -euxo pipefail
33

44
echo "Hello: PREFIX='$PREFIX'"
55
echo "LD_LIBRARY_PATH: ${LD_LIBRARY_PATH:-}"
6-
echo "OLD_LD_LIBRARY_PATH: ${OLD_LD_LIBRARY_PATH:-}"

examples/scripts/post_install.sh

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,43 @@ test "${CUSTOM_VARIABLE_2}" = '$ECOND-CUSTOM_'\''STRING'\'' WITH SPACES AND @*!
2323

2424
test "${INSTALLER_UNATTENDED}" = "1"
2525

26-
if [[ $(uname -s) == Linux ]]; then
26+
# Print to stderr if any of the input variables are set, and returns 1 - otherwise 0.
27+
# Note that variables that are set but are empty strings will also trigger an error.
28+
# All input variables are checked before exit.
29+
verify_var_is_unset() {
30+
local failed=0
31+
for var in "$@"; do
32+
if [[ -n "${!var+x}" ]]; then
33+
echo "Error: environment variable $var must be unset." >&2
34+
failed=1
35+
fi
36+
done
37+
return $failed
38+
}
39+
40+
if [[ $(uname -s) == "Linux" ]]; then
2741
if [[ ${INSTALLER_PLAT} != linux-* ]]; then
42+
echo "Error: INSTALLER_PLAT must match 'linux-*' on Linux systems."
43+
exit 1
44+
fi
45+
46+
if ! verify_var_is_unset LD_LIBRARY_PATH LD_PRELOAD LD_AUDIT; then
47+
echo "Error: One or more of LD_LIBRARY_PATH, LD_PRELOAD, or LD_AUDIT are set."
2848
exit 1
2949
fi
50+
3051
else # macOS
3152
if [[ ${INSTALLER_PLAT} != osx-* ]]; then
53+
echo "Error: INSTALLER_PLAT must match 'osx-*' on macOS systems."
54+
exit 1
55+
fi
56+
57+
if ! verify_var_is_unset \
58+
DYLD_LIBRARY_PATH \
59+
DYLD_FALLBACK_LIBRARY_PATH \
60+
DYLD_INSERT_LIBRARIES \
61+
DYLD_FRAMEWORK_PATH; then
62+
echo "Error: One or more DYLD_* environment variables are set."
3263
exit 1
3364
fi
3465
fi

news/1082-unset-variables

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
### Enhancements
2+
3+
* Unset additional environment variables in shell-based installers to avoid accidental loading of external libraries. (#1082)
4+
5+
### Bug fixes
6+
7+
* <news item>
8+
9+
### Deprecations
10+
11+
* <news item>
12+
13+
### Docs
14+
15+
* <news item>
16+
17+
### Other
18+
19+
* <news item>

0 commit comments

Comments
 (0)