summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2021-01-10 16:34:29 +0000
committerAlexander Larsson <alexander.larsson@gmail.com>2021-01-14 09:33:24 +0100
commitb0aea9c0533f8338ead9acb8dd2a65e6339b9a99 (patch)
treef04d9ce7034e6546be7627d5ee3e7a5095114bf3
parente2c4ded323161f47609d0af97d00019d04a635f1 (diff)
downloadflatpak-b0aea9c0533f8338ead9acb8dd2a65e6339b9a99.tar.gz
run: Allow setting environment variables to empty strings
Some consumers of environment variables distinguish between present with an empty value and absent. For example, if an environment variable represents a search path like VK_ICD_FILENAMES, unsetting it often results in use of a default, but setting it to the empty string results in not searching any locations, which is sometimes what is desired. The shell syntax "${BAR-unset}" expands to the value of ${BAR} if it is set to anything (even an empty string), or to "unset" if not. We can use that in the unit test to check that BAR is set to the empty string in this case. This follows up from GHSA-4ppf-fxf6-vxg2 to fix an issue that I noticed while resolving that vulnerability, but is not required for fixing the vulnerability. Signed-off-by: Simon McVittie <smcv@collabora.com>
-rw-r--r--common/flatpak-run.c2
-rwxr-xr-xtests/test-override.sh2
2 files changed, 2 insertions, 2 deletions
diff --git a/common/flatpak-run.c b/common/flatpak-run.c
index c69f2c38..7e657251 100644
--- a/common/flatpak-run.c
+++ b/common/flatpak-run.c
@@ -1678,7 +1678,7 @@ flatpak_run_apply_env_vars (FlatpakBwrap *bwrap, FlatpakContext *context)
const char *var = key;
const char *val = value;
- if (val && val[0] != 0)
+ if (val)
flatpak_bwrap_set_env (bwrap, var, val, TRUE);
else
flatpak_bwrap_unset_env (bwrap, var);
diff --git a/tests/test-override.sh b/tests/test-override.sh
index 8a0dc1c5..48211ffe 100755
--- a/tests/test-override.sh
+++ b/tests/test-override.sh
@@ -95,7 +95,7 @@ if skip_one_without_bwrap "sandbox environment variables"; then
:
else
${FLATPAK} run --command=bash org.test.Hello \
- -c 'echo "FOO=$FOO"; echo "BAR=$BAR"; echo "SECRET_TOKEN=$SECRET_TOKEN"; echo "TMPDIR=$TMPDIR"; echo "TZDIR=$TZDIR"' > out
+ -c 'echo "FOO=$FOO"; echo "BAR=${BAR-unset}"; echo "SECRET_TOKEN=$SECRET_TOKEN"; echo "TMPDIR=$TMPDIR"; echo "TZDIR=$TZDIR"' > out
assert_file_has_content out '^FOO=BAR$'
assert_file_has_content out '^BAR=$'
assert_file_has_content out '^SECRET_TOKEN=3047225e-5e38-4357-b21c-eac83b7e8ea6$'