From: Paul Smith Date: Tue, 23 May 2023 03:36:13 +0000 (-0400) Subject: [SV 64815] Recipe lines cannot contain conditional statements X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=07fcee35f058a876447c8a021f9eb1943f902534;p=thirdparty%2Fmake.git [SV 64815] Recipe lines cannot contain conditional statements * 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. --- diff --git a/NEWS b/NEWS index 16348d67..2aee1f1d 100644 --- 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. diff --git a/src/read.c b/src/read.c index 4e8432a0..6748486e 100644 --- a/src/read.c +++ b/src/read.c @@ -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; diff --git a/tests/scripts/features/conditionals b/tests/scripts/features/conditionals index ead3b7eb..c1eee95c 100644 --- a/tests/scripts/features/conditionals +++ b/tests/scripts/features/conditionals @@ -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;