]> git.ipfire.org Git - thirdparty/make.git/commitdiff
[SV 59230] Ensure environment variables are exportable
authorPaul Smith <psmith@gnu.org>
Fri, 27 Nov 2020 21:56:22 +0000 (16:56 -0500)
committerPaul Smith <psmith@gnu.org>
Sun, 29 Nov 2020 22:55:32 +0000 (17:55 -0500)
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 <dgoncharov@users.sf.net> 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
tests/scripts/features/targetvars

index d9e1a4a6cd30f41ed92e3adbd08f682dc3161df8..94e925fbd33b79905424868588661dfe25da09eb 100644 (file)
@@ -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;
index 66c7ce2d3bcb0f430ba2d79e13a5638f8d72924f..08263bf34c57d91c14d7d4732bab895a2a256dd2 100644 (file)
@@ -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('