Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make make: fix null pointer when including empty fil...
details: https://anonhg.NetBSD.org/src/rev/7d3a07386cf5
branches: trunk
changeset: 359465:7d3a07386cf5
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Jan 07 08:20:00 2022 +0000
description:
make: fix null pointer when including empty file (since 2022-01-01)
Calling malloc(0) may return a null pointer, but callers of bmake_malloc
do not expect that.
Reported by Chris Pinnock, found by cross-compiling NetBSD on OpenBSD,
where tools/groff creates Makefile.dep files of size 0.
diffstat:
usr.bin/make/parse.c | 6 +++---
usr.bin/make/unit-tests/directive-include.mk | 13 ++++++++++++-
2 files changed, 15 insertions(+), 4 deletions(-)
diffs (52 lines):
diff -r 4552c17ff7d4 -r 7d3a07386cf5 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c Fri Jan 07 07:34:10 2022 +0000
+++ b/usr.bin/make/parse.c Fri Jan 07 08:20:00 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.619 2022/01/02 02:57:39 rillig Exp $ */
+/* $NetBSD: parse.c,v 1.620 2022/01/07 08:20:00 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -106,7 +106,7 @@
#include "pathnames.h"
/* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: parse.c,v 1.619 2022/01/02 02:57:39 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.620 2022/01/07 08:20:00 rillig Exp $");
/*
* Structure for a file being read ("included file")
@@ -297,7 +297,7 @@
struct stat st;
bufSize = fstat(fd, &st) == 0 && S_ISREG(st.st_mode) &&
- st.st_size >= 0 && st.st_size <= 0x3fffffff
+ st.st_size >= 1 && st.st_size <= 0x3fffffff
? (size_t)st.st_size : 1024;
Buf_InitSize(&buf, bufSize);
diff -r 4552c17ff7d4 -r 7d3a07386cf5 usr.bin/make/unit-tests/directive-include.mk
--- a/usr.bin/make/unit-tests/directive-include.mk Fri Jan 07 07:34:10 2022 +0000
+++ b/usr.bin/make/unit-tests/directive-include.mk Fri Jan 07 08:20:00 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: directive-include.mk,v 1.9 2021/12/14 01:00:04 rillig Exp $
+# $NetBSD: directive-include.mk,v 1.10 2022/01/07 08:20:00 rillig Exp $
#
# Tests for the .include directive, which includes another file.
@@ -71,4 +71,15 @@
# or any other indicator for the empty filename at the end of the line.
#include ${:U}
+
+# Since parse.c 1.612 from 2022-01-01 and before parse.c 1.620 from
+# 2022-01-07, including an empty regular file called bmake_malloc(0), which
+# may return a null pointer. On OpenBSD, this led to a segmentation fault in
+# Buf_InitSize, which assumes that bmake_malloc never returns NULL, just like
+# all other places in the code.
+_!= > directive-include-empty
+.include "${.CURDIR}/directive-include-empty"
+_!= rm directive-include-empty
+
+
all:
Home |
Main Index |
Thread Index |
Old Index