Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make Guarantee no arithmetic overflow.
details: https://anonhg.NetBSD.org/src/rev/6b3ed4a8a250
branches: trunk
changeset: 352985:6b3ed4a8a250
user: riastradh <riastradh%NetBSD.org@localhost>
date: Sun Apr 16 21:03:13 2017 +0000
description:
Guarantee no arithmetic overflow.
diffstat:
usr.bin/make/parse.c | 13 ++++++++++---
1 files changed, 10 insertions(+), 3 deletions(-)
diffs (50 lines):
diff -r b188f916109c -r 6b3ed4a8a250 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c Sun Apr 16 20:59:04 2017 +0000
+++ b/usr.bin/make/parse.c Sun Apr 16 21:03:13 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.220 2017/04/16 20:00:58 maya Exp $ */
+/* $NetBSD: parse.c,v 1.221 2017/04/16 21:03:13 riastradh Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.220 2017/04/16 20:00:58 maya Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.221 2017/04/16 21:03:13 riastradh 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.220 2017/04/16 20:00:58 maya Exp $");
+__RCSID("$NetBSD: parse.c,v 1.221 2017/04/16 21:03:13 riastradh Exp $");
#endif
#endif /* not lint */
#endif
@@ -129,6 +129,7 @@
#include <assert.h>
#include <ctype.h>
#include <errno.h>
+#include <limits.h>
#include <stdarg.h>
#include <stdio.h>
@@ -548,9 +549,15 @@
while (1) {
assert(bufpos <= lf->len);
if (bufpos == lf->len) {
+ if (lf->len > SIZE_MAX/2) {
+ errno = EFBIG;
+ Error("%s: file too large", path);
+ exit(1);
+ }
lf->len *= 2;
lf->buf = bmake_realloc(lf->buf, lf->len);
}
+ assert(bufpos < lf->len);
result = read(fd, lf->buf + bufpos, lf->len - bufpos);
if (result < 0) {
Error("%s: read error: %s", path, strerror(errno));
Home |
Main Index |
Thread Index |
Old Index