Module Name: src
Committed By: rillig
Date: Mon Nov 2 22:50:55 UTC 2020
Modified Files:
src/usr.bin/make: parse.c
Log Message:
make(1): fix undefined behavior in Parse_IsVar
Even though the pointer was out-of-bounds, a crash was unlikely in
practice, since typical C compilers don't check the pointers for invalid
values after each modification. The memory it pointed to was not
accessed though.
To generate a diff of this commit:
cvs rdiff -u -r1.421 -r1.422 src/usr.bin/make/parse.c
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/parse.c
diff -u src/usr.bin/make/parse.c:1.421 src/usr.bin/make/parse.c:1.422
--- src/usr.bin/make/parse.c:1.421 Mon Nov 2 22:44:29 2020
+++ src/usr.bin/make/parse.c Mon Nov 2 22:50:55 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.421 2020/11/02 22:44:29 rillig Exp $ */
+/* $NetBSD: parse.c,v 1.422 2020/11/02 22:50:55 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -117,7 +117,7 @@
#include "pathnames.h"
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.421 2020/11/02 22:44:29 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.422 2020/11/02 22:50:55 rillig Exp $");
/* types and constants */
@@ -1832,7 +1832,6 @@ Parse_IsVar(const char *p, VarAssign *ou
{
VarAssignParsed pvar;
const char *firstSpace = NULL;
- char ch;
int level = 0;
/* Skip to variable name */
@@ -1850,9 +1849,8 @@ Parse_IsVar(const char *p, VarAssign *ou
#endif
/* Scan for one of the assignment operators outside a variable expansion */
- /* FIXME: undefined behavior. In unit-tests/varname.mk:try1, at the end
- * of the loop, p already points to the next line. */
- while ((ch = *p++) != 0) {
+ while (*p != '\0') {
+ char ch = *p++;
if (ch == '(' || ch == '{') {
level++;
continue;