Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make loadfile: in the mmap case ensures that the buf...



details:   https://anonhg.NetBSD.org/src/rev/96109159fd55
branches:  trunk
changeset: 822108:96109159fd55
user:      sjg <sjg%NetBSD.org@localhost>
date:      Wed Mar 01 16:39:49 2017 +0000

description:
loadfile: in the mmap case ensures that the buffer ends with \n
do the same for the non-mmap case - avoids core dump.

diffstat:

 usr.bin/make/parse.c |  10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diffs (38 lines):

diff -r f6b42d55daf2 -r 96109159fd55 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Wed Mar 01 16:27:25 2017 +0000
+++ b/usr.bin/make/parse.c      Wed Mar 01 16:39:49 2017 +0000
@@ -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 @@
 
        /* 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:



Home | Main Index | Thread Index | Old Index