Module Name: src
Committed By: sjg
Date: Wed Mar 1 16:39:49 UTC 2017
Modified Files:
src/usr.bin/make: parse.c
Log Message:
loadfile: in the mmap case ensures that the buffer ends with \n
do the same for the non-mmap case - avoids core dump.
To generate a diff of this commit:
cvs rdiff -u -r1.217 -r1.218 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.217 src/usr.bin/make/parse.c:1.218
--- src/usr.bin/make/parse.c:1.217 Fri Dec 9 22:56:21 2016
+++ src/usr.bin/make/parse.c Wed Mar 1 16:39:49 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.217 2016/12/09 22:56:21 sjg Exp $ */
+/* $NetBSD: parse.c,v 1.218 2017/03/01 16:39:49 sjg Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.217 2016/12/09 22:56:21 sjg Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.218 2017/03/01 16:39:49 sjg Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: parse.c,v 1.217 2016/12/09 22:56:21 sjg Exp $");
+__RCSID("$NetBSD: parse.c,v 1.218 2017/03/01 16:39:49 sjg Exp $");
#endif
#endif /* not lint */
#endif
@@ -566,7 +566,11 @@ loadfile(const char *path, int fd)
/* truncate malloc region to actual length (maybe not useful) */
if (lf->len > 0) {
+ /* as for mmap case, ensure trailing \n */
+ if (lf->buf[lf->len - 1] != '\n')
+ lf->len++;
lf->buf = bmake_realloc(lf->buf, lf->len);
+ lf->buf[lf->len - 1] = '\n';
}
done: