Module Name: src Committed By: rillig Date: Tue Jan 19 18:13:37 UTC 2021
Modified Files: src/usr.bin/make: cond.c src/usr.bin/make/unit-tests: cond-op.exp cond-op.mk Log Message: make(1): add error handling for edge case in malformed conditions To generate a diff of this commit: cvs rdiff -u -r1.237 -r1.238 src/usr.bin/make/cond.c cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/cond-op.exp cvs rdiff -u -r1.11 -r1.12 src/usr.bin/make/unit-tests/cond-op.mk Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/cond.c diff -u src/usr.bin/make/cond.c:1.237 src/usr.bin/make/cond.c:1.238 --- src/usr.bin/make/cond.c:1.237 Tue Jan 19 17:57:07 2021 +++ src/usr.bin/make/cond.c Tue Jan 19 18:13:37 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: cond.c,v 1.237 2021/01/19 17:57:07 rillig Exp $ */ +/* $NetBSD: cond.c,v 1.238 2021/01/19 18:13:37 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -95,7 +95,7 @@ #include "dir.h" /* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */ -MAKE_RCSID("$NetBSD: cond.c,v 1.237 2021/01/19 17:57:07 rillig Exp $"); +MAKE_RCSID("$NetBSD: cond.c,v 1.238 2021/01/19 18:13:37 rillig Exp $"); /* * The parsing of conditional expressions is based on this grammar: @@ -980,7 +980,8 @@ CondParser_Factor(CondParser *par, Boole if (l == TOK_TRUE) { l = CondParser_Factor(par, doEval); } else { - (void)CondParser_Factor(par, FALSE); + if (CondParser_Factor(par, FALSE) == TOK_ERROR) + return TOK_ERROR; } } else { /* @@ -1023,7 +1024,8 @@ CondParser_Expr(CondParser *par, Boolean if (l == TOK_FALSE) { l = CondParser_Expr(par, doEval); } else { - (void)CondParser_Expr(par, FALSE); + if (CondParser_Expr(par, FALSE) == TOK_ERROR) + return TOK_ERROR; } } else { /* Index: src/usr.bin/make/unit-tests/cond-op.exp diff -u src/usr.bin/make/unit-tests/cond-op.exp:1.8 src/usr.bin/make/unit-tests/cond-op.exp:1.9 --- src/usr.bin/make/unit-tests/cond-op.exp:1.8 Tue Jan 19 18:09:12 2021 +++ src/usr.bin/make/unit-tests/cond-op.exp Tue Jan 19 18:13:37 2021 @@ -12,8 +12,8 @@ make: "cond-op.mk" line 93: 1 0 1 => make: "cond-op.mk" line 93: 1 1 0 => 0 1 1 make: "cond-op.mk" line 93: 1 1 1 => 1 1 1 make: "cond-op.mk" line 104: Malformed conditional (1 &&) -make: "cond-op.mk" line 115: Missing argument for ".error" -make: "cond-op.mk" line 121: Missing argument for ".error" +make: "cond-op.mk" line 112: Malformed conditional (0 &&) +make: "cond-op.mk" line 120: Malformed conditional (1 ||) make: "cond-op.mk" line 129: Malformed conditional (0 ||) make: Fatal errors encountered -- cannot continue make: stopped in unit-tests Index: src/usr.bin/make/unit-tests/cond-op.mk diff -u src/usr.bin/make/unit-tests/cond-op.mk:1.11 src/usr.bin/make/unit-tests/cond-op.mk:1.12 --- src/usr.bin/make/unit-tests/cond-op.mk:1.11 Tue Jan 19 18:09:12 2021 +++ src/usr.bin/make/unit-tests/cond-op.mk Tue Jan 19 18:13:37 2021 @@ -1,4 +1,4 @@ -# $NetBSD: cond-op.mk,v 1.11 2021/01/19 18:09:12 rillig Exp $ +# $NetBSD: cond-op.mk,v 1.12 2021/01/19 18:13:37 rillig Exp $ # # Tests for operators like &&, ||, ! in .if conditions. # @@ -107,16 +107,16 @@ . error .endif -# FIXME: Don't accept this condition as syntactically valid. -# FIXME: CondParser_Factor, (void). +# This obviously malformed condition was not detected as such before cond.c +# 1.238 from 2021-01-19. .if 0 && . error .else . error .endif -# FIXME: Don't accept this condition as syntactically valid. -# FIXME: CondParser_Expr, (void). +# This obviously malformed condition was not detected as such before cond.c +# 1.238 from 2021-01-19. .if 1 || . error .else