Module Name:    src
Committed By:   rillig
Date:           Sat Oct 31 23:10:07 UTC 2020

Modified Files:
        src/usr.bin/make: parse.c

Log Message:
make(1): improve local variable name in ParseTrackInput

By the way, the Address Sanitizer that ran over this code on 2015-11-26
didn't find the other out-of-bounds bug.  Most probably the Address
Sanitizer only detected obvious bugs in the actual test data, and there
was no test case in which .MAKE.MAKEFILES was shorter than the newly
added makefile.


To generate a diff of this commit:
cvs rdiff -u -r1.416 -r1.417 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.416 src/usr.bin/make/parse.c:1.417
--- src/usr.bin/make/parse.c:1.416	Sat Oct 31 23:01:23 2020
+++ src/usr.bin/make/parse.c	Sat Oct 31 23:10:06 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.416 2020/10/31 23:01:23 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.417 2020/10/31 23:10:06 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.416 2020/10/31 23:01:23 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.417 2020/10/31 23:10:06 rillig Exp $");
 
 /* types and constants */
 
@@ -2356,11 +2356,12 @@ ParseSetParseFile(const char *filename)
 static void
 ParseTrackInput(const char *name)
 {
-    void *fp = NULL;
+    void *old_freeIt = NULL;
 
-    const char *old = Var_Value(MAKE_MAKEFILES, VAR_GLOBAL, &fp);
-    if (old) {
+    const char *old = Var_Value(MAKE_MAKEFILES, VAR_GLOBAL, &old_freeIt);
+    if (old != NULL) {
 	size_t name_len = strlen(name);
+	/* XXX: undefined behavior if name_len > strlen(old) */
 	const char *ep = old + strlen(old) - name_len;
 	/* does it contain name? */
 	for (; old != NULL; old = strchr(old, ' ')) {
@@ -2375,7 +2376,7 @@ ParseTrackInput(const char *name)
     }
     Var_Append(MAKE_MAKEFILES, name, VAR_GLOBAL);
 cleanup:
-    bmake_free(fp);
+    bmake_free(old_freeIt);
 }
 
 

Reply via email to