From 1b370898b97faafc90312addde81588d7d14736f Mon Sep 17 00:00:00 2001 From: sjg Date: Wed, 1 Mar 2017 16:39:49 +0000 Subject: [PATCH] loadfile: in the mmap case ensures that the buffer ends with \n do the same for the non-mmap case - avoids core dump. --- usr.bin/make/parse.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c index 7bf9dddb783b..80af7b5fe3f6 100644 --- a/usr.bin/make/parse.c +++ b/usr.bin/make/parse.c @@ -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 #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: