Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/stdlib die if integer overflow. from openbsd
details: https://anonhg.NetBSD.org/src/rev/41f8f47c9397
branches: trunk
changeset: 534598:41f8f47c9397
user: itojun <itojun%NetBSD.org@localhost>
date: Tue Jul 30 09:45:02 2002 +0000
description:
die if integer overflow. from openbsd
diffstat:
lib/libc/stdlib/calloc.c | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)
diffs (36 lines):
diff -r c6d2fe94aa9c -r 41f8f47c9397 lib/libc/stdlib/calloc.c
--- a/lib/libc/stdlib/calloc.c Tue Jul 30 09:11:27 2002 +0000
+++ b/lib/libc/stdlib/calloc.c Tue Jul 30 09:45:02 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: calloc.c,v 1.9 1998/02/03 18:44:14 perry Exp $ */
+/* $NetBSD: calloc.c,v 1.10 2002/07/30 09:45:02 itojun Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -38,12 +38,14 @@
#if 0
static char sccsid[] = "@(#)calloc.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: calloc.c,v 1.9 1998/02/03 18:44:14 perry Exp $");
+__RCSID("$NetBSD: calloc.c,v 1.10 2002/07/30 09:45:02 itojun Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
#include <stdlib.h>
#include <string.h>
+#include <limits.h>
+#include <errno.h>
void *
calloc(num, size)
@@ -52,6 +54,10 @@
{
void *p;
+ if (SIZE_T_MAX / num < size) {
+ errno = ENOMEM;
+ return NULL;
+ }
size *= num;
if ((p = malloc(size)) != NULL)
memset(p, '\0', size);
Home |
Main Index |
Thread Index |
Old Index