]> git.ipfire.org Git - thirdparty/make.git/commitdiff
* src/read.c (eval): [SV 40942] Allow targets named "load"
authorPaul Smith <psmith@gnu.org>
Sat, 6 May 2023 20:12:11 +0000 (16:12 -0400)
committerPaul Smith <psmith@gnu.org>
Sun, 7 May 2023 20:51:06 +0000 (16:51 -0400)
Previously "load:" worked but "load :" failed.  Allow the latter as
well.  This doesn't fix all issues; "load foo :" is still treated
as a load operation for "foo" and ":".  Avoids SV 50413 as well.
* tests/scripts/features/load: Write tests.

src/read.c
tests/scripts/features/load

index 3909fc649edce2c69a09817ab8b95f2f4e29f3b6..4e8432a0745c3c801c766e4e59ec9fb627df276a 100644 (file)
@@ -621,6 +621,7 @@ eval (struct ebuffer *ebuf, int set_default)
       size_t wlen;
       char *p;
       char *p2;
+      unsigned int is_rule;
       struct vmodifiers vmod;
 
       /* At the top of this loop, we are starting a brand new line.  */
@@ -760,6 +761,8 @@ eval (struct ebuffer *ebuf, int set_default)
       wlen = p2 - p;
       NEXT_TOKEN (p2);
 
+      is_rule = *p2 == ':' || ((*p2 == '&' || *p2 == '|') && p2[1] == ':');
+
       /* If we're in an ignored define, skip this line (but maybe get out).  */
       if (in_ignored_define)
         {
@@ -910,8 +913,8 @@ eval (struct ebuffer *ebuf, int set_default)
           continue;
         }
 
-      /* Handle the load operations.  */
-      if (word1eq ("load") || word1eq ("-load"))
+      /* Handle the load operations.  Allow targets named "load".  */
+      if ((word1eq ("load") || word1eq ("-load")) && !is_rule)
         {
           /* A 'load' line specifies a dynamic object to load.  */
           struct nameseq *files;
index b462ed9cca572031865bda5ea7bc73ab510e96a0..3713f9449267e117b9dc7626f90259100fede980 100644 (file)
@@ -144,7 +144,25 @@ all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD)
 testload.so: testload.c ; @echo "rebuilding $@"; !.$sobuild,
               '', "pre= post=testload.so implicit\n");
 
-unlink(qw(testload.c testload.so)) unless $keep;
+# Check using load as a target or variable name
+run_make_test(q!
+load: ; @echo $@
+-load&: ; @echo $@
+!,
+              "", "load\n");
+
+run_make_test(q!
+load : ; @echo $@
+-load &: ; echo $@
+!,
+              "", "load\n");
+
+run_make_test(q!
+load = @echo $@
+all: ; $(load)
+load |: ; echo $@
+!,
+              "", "all\n");
 
 # This tells the test driver that the perl test script executed properly.
 1;