Module Name:    src
Committed By:   rillig
Date:           Sun Dec  6 18:37:04 UTC 2020

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

Log Message:
make(1): fix undefined behavior in ParseEOF

Adding a number to a null pointer should have been caught by any
Undefined Behavior Sanitizer, but apparently neither GCC nor Clang do
this.


To generate a diff of this commit:
cvs rdiff -u -r1.469 -r1.470 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.469 src/usr.bin/make/parse.c:1.470
--- src/usr.bin/make/parse.c:1.469	Sat Dec  5 19:46:04 2020
+++ src/usr.bin/make/parse.c	Sun Dec  6 18:37:04 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.469 2020/12/05 19:46:04 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.470 2020/12/06 18:37:04 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.469 2020/12/05 19:46:04 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.470 2020/12/06 18:37:04 rillig Exp $");
 
 /* types and constants */
 
@@ -2623,7 +2623,7 @@ ParseEOF(void)
 	ptr = curFile->nextbuf(curFile->nextbuf_arg, &len);
 	curFile->buf_ptr = ptr;
 	curFile->buf_freeIt = ptr;
-	curFile->buf_end = ptr + len; /* XXX: undefined behavior if ptr == NULL */
+	curFile->buf_end = ptr == NULL ? NULL : ptr + len;
 	curFile->lineno = curFile->first_lineno;
 	if (ptr != NULL)
 		return TRUE;	/* Iterate again */

Reply via email to