summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2007-09-02 15:19:41 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2007-09-02 15:19:41 +0000
commit6ebd04219f0d749c87a763e8afb578dfcd5223cc (patch)
treebb0f29e0a3791fff88551c93f5d4ba7113bdba43 /lib/libc/stdlib
parentbe524287dc216d876f995eddcaf32762c702c6e9 (diff)
use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg
Diffstat (limited to 'lib/libc/stdlib')
-rw-r--r--lib/libc/stdlib/hcreate.c4
-rw-r--r--lib/libc/stdlib/radixsort.c4
2 files changed, 4 insertions, 4 deletions
diff --git a/lib/libc/stdlib/hcreate.c b/lib/libc/stdlib/hcreate.c
index f8df1bcd7c9..094f32c173e 100644
--- a/lib/libc/stdlib/hcreate.c
+++ b/lib/libc/stdlib/hcreate.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hcreate.c,v 1.3 2005/10/10 17:37:44 espie Exp $ */
+/* $OpenBSD: hcreate.c,v 1.4 2007/09/02 15:19:17 deraadt Exp $ */
/* $NetBSD: hcreate.c,v 1.5 2004/04/23 02:48:12 simonb Exp $ */
/*
@@ -117,7 +117,7 @@ hcreate(size_t nel)
/* Allocate the table. */
htablesize = nel;
- htable = malloc(htablesize * sizeof htable[0]);
+ htable = calloc(htablesize, sizeof htable[0]);
if (htable == NULL) {
errno = ENOMEM;
return 0;
diff --git a/lib/libc/stdlib/radixsort.c b/lib/libc/stdlib/radixsort.c
index 0b2ff27044f..49d03b52d5d 100644
--- a/lib/libc/stdlib/radixsort.c
+++ b/lib/libc/stdlib/radixsort.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: radixsort.c,v 1.8 2005/08/08 08:05:37 espie Exp $ */
+/* $OpenBSD: radixsort.c,v 1.9 2007/09/02 15:19:17 deraadt Exp $ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -104,7 +104,7 @@ sradixsort(const u_char **a, int n, const u_char *tab, u_int endch)
if (n < THRESHOLD)
simplesort(a, n, 0, tr, endch);
else {
- if ((ta = malloc(n * sizeof(a))) == NULL)
+ if ((ta = calloc(n, sizeof(a))) == NULL)
return (-1);
r_sort_b(a, ta, n, 0, tr, endch);
free(ta);