]> git.ipfire.org Git - thirdparty/make.git/commitdiff
[SV 64815] Recipe lines cannot contain conditional statements
authorPaul Smith <psmith@gnu.org>
Tue, 23 May 2023 03:36:13 +0000 (23:36 -0400)
committerPaul Smith <psmith@gnu.org>
Tue, 23 May 2023 03:36:13 +0000 (23:36 -0400)
* NEWS: Mention this change.
* src/read.c (eval): Check for ignoring for any line even if not
in a rule context.
* tests/scripts/features/conditionals: Write new tests.

NEWS
src/read.c
tests/scripts/features/conditionals

diff --git a/NEWS b/NEWS
index 16348d67c322ac97bac44ad39b7e053fefcc28bc..2aee1f1d76d457cb4bf8d2fd60e7b0297ea745e1 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -53,6 +53,10 @@ https://sv.gnu.org/bugs/index.php?group=make&report_id=111&fix_release_id=111&se
   invoked recursively, warnings can be controlled only for the current
   instance of make using the .WARNINGS variable.
 
+* Conditional statements starting with the recipe prefix were sometimes
+  interpreted in previous versions.  As per the documentation, lines starting
+  with the recipe prefix are now never considered conditional statements.
+
 * Tests in the regression test suite now are run in their own directory to
   avoid cross-contamination and allow cleanup if the tests are interrupted.
   More information is printed about failing tests.
index 4e8432a0745c3c801c766e4e59ec9fb627df276a..6748486e76069af71c8759868389f35573a58395 100644 (file)
@@ -666,16 +666,16 @@ eval (struct ebuffer *ebuf, int set_default)
             /* Ignore the commands in a rule with no targets.  */
             continue;
 
+          if (ignoring)
+            /* Yep, this is a shell command, and we don't care.  */
+            continue;
+
           /* If there is no preceding rule line, don't treat this line
              as a command, even though it begins with a recipe prefix.
              SunOS 4 make appears to behave this way.  */
 
           if (filenames != 0)
             {
-              if (ignoring)
-                /* Yep, this is a shell command, and we don't care.  */
-                continue;
-
               if (commands_idx == 0)
                 cmds_started = ebuf->floc.lineno;
 
index ead3b7ebea869d28bfc91105958e4129882f0e27..c1eee95c45290e9d78a22f4c176f19c9c030986b 100644 (file)
@@ -153,6 +153,67 @@ endif
 ',
               '', "one\n");
 
+# SV 64085: Ensure recipe prefixed conditionals are never considered
+run_make_test(q!
+blah=1
+ifdef blah
+else
+       else
+endif
+all:;
+!,
+    '', "#MAKE#: 'all' is up to date.");
+
+run_make_test(q!
+blah=1
+ifdef blah
+else
+       endif
+endif
+all:;
+!,
+    '', "#MAKE#: 'all' is up to date.");
+
+run_make_test(q!
+blah=1
+ifdef blah
+else
+       ifdef blah
+endif
+all:;
+!,
+    '', "#MAKE#: 'all' is up to date.");
+
+run_make_test(q!
+blah=1
+all:;
+foo:
+ifdef blah
+       ifdef blah
+endif
+!,
+    '', "#MAKE#: 'all' is up to date.");
+
+run_make_test(q!
+blah=1
+all:;
+foo:
+ifdef blah
+       endif
+endif
+!,
+    '', "#MAKE#: 'all' is up to date.");
+
+run_make_test(q!
+blah=1
+all:;
+foo:
+ifdef blah
+       else
+else
+endif
+!,
+    '', "#MAKE#: 'all' is up to date.");
 
 # This tells the test driver that the perl test script executed properly.
 1;