From 19ae6fe72ace81bd16f02bd40635bbc766e53c95 Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Fri, 27 Nov 2020 16:56:22 -0500 Subject: [PATCH] [SV 59230] Ensure environment variables are exportable When checking for invalid environment variable names we searched the entire name string instead of just the first LENGTH chars; this could cause us to incorrectly decide the variable was not exportable. Dmitry Goncharov found this bug and provided a test case and sample fix: I used the test but chose a slightly different fix. * src/variable.c (define_variable_in_set): check the variable name not the input string. * tests/scripts/features/targetvars: Ensure environment variable values are exported. --- src/variable.c | 2 ++ tests/scripts/features/targetvars | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/variable.c b/src/variable.c index d9e1a4a6..94e925fb 100644 --- a/src/variable.c +++ b/src/variable.c @@ -282,6 +282,8 @@ define_variable_in_set (const char *name, size_t length, v->export = v_default; v->exportable = 1; + /* Check the nul-terminated variable name. */ + name = v->name; if (*name != '_' && (*name < 'A' || *name > 'Z') && (*name < 'a' || *name > 'z')) v->exportable = 0; diff --git a/tests/scripts/features/targetvars b/tests/scripts/features/targetvars index 66c7ce2d..08263bf3 100644 --- a/tests/scripts/features/targetvars +++ b/tests/scripts/features/targetvars @@ -281,6 +281,16 @@ all: ; $sname unlink("sd/$sname"); rmdir ('sd'); +# SV 59230: Conditional (non-)assignment of target-specific variables should +# preserve export settings. + +$ENV{hello} = 'moon'; +run_make_test(q! +all:; @echo hello=$$hello +dummy: hello?=world +!, + '', 'hello=moon'); + # TEST #19: Test define/endef variables as target-specific vars # run_make_test('