summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib
diff options
context:
space:
mode:
authorderaadt <>2007-09-02 15:19:18 +0000
committerderaadt <>2007-09-02 15:19:18 +0000
commit4dce4206f0cafd0811f23aedc04a436aa9d145c1 (patch)
tree9bdb3d7b5724b183b1a397bf8f071fac1f056834 /src/lib/libc/stdlib
parent7c27b50830c6058e8a7d8f2a3398c9c2f429b9f4 (diff)
downloadopenbsd-4dce4206f0cafd0811f23aedc04a436aa9d145c1.tar.gz
openbsd-4dce4206f0cafd0811f23aedc04a436aa9d145c1.tar.bz2
openbsd-4dce4206f0cafd0811f23aedc04a436aa9d145c1.zip
use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg
Diffstat (limited to 'src/lib/libc/stdlib')
-rw-r--r--src/lib/libc/stdlib/hcreate.c4
-rw-r--r--src/lib/libc/stdlib/radixsort.c4
2 files changed, 4 insertions, 4 deletions
diff --git a/src/lib/libc/stdlib/hcreate.c b/src/lib/libc/stdlib/hcreate.c
index f8df1bcd7c..094f32c173 100644
--- a/src/lib/libc/stdlib/hcreate.c
+++ b/src/lib/libc/stdlib/hcreate.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: hcreate.c,v 1.3 2005/10/10 17:37:44 espie Exp $ */ 1/* $OpenBSD: hcreate.c,v 1.4 2007/09/02 15:19:17 deraadt Exp $ */
2/* $NetBSD: hcreate.c,v 1.5 2004/04/23 02:48:12 simonb Exp $ */ 2/* $NetBSD: hcreate.c,v 1.5 2004/04/23 02:48:12 simonb Exp $ */
3 3
4/* 4/*
@@ -117,7 +117,7 @@ hcreate(size_t nel)
117 117
118 /* Allocate the table. */ 118 /* Allocate the table. */
119 htablesize = nel; 119 htablesize = nel;
120 htable = malloc(htablesize * sizeof htable[0]); 120 htable = calloc(htablesize, sizeof htable[0]);
121 if (htable == NULL) { 121 if (htable == NULL) {
122 errno = ENOMEM; 122 errno = ENOMEM;
123 return 0; 123 return 0;
diff --git a/src/lib/libc/stdlib/radixsort.c b/src/lib/libc/stdlib/radixsort.c
index 0b2ff27044..49d03b52d5 100644
--- a/src/lib/libc/stdlib/radixsort.c
+++ b/src/lib/libc/stdlib/radixsort.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: radixsort.c,v 1.8 2005/08/08 08:05:37 espie Exp $ */ 1/* $OpenBSD: radixsort.c,v 1.9 2007/09/02 15:19:17 deraadt Exp $ */
2/*- 2/*-
3 * Copyright (c) 1990, 1993 3 * Copyright (c) 1990, 1993
4 * The Regents of the University of California. All rights reserved. 4 * 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)
104 if (n < THRESHOLD) 104 if (n < THRESHOLD)
105 simplesort(a, n, 0, tr, endch); 105 simplesort(a, n, 0, tr, endch);
106 else { 106 else {
107 if ((ta = malloc(n * sizeof(a))) == NULL) 107 if ((ta = calloc(n, sizeof(a))) == NULL)
108 return (-1); 108 return (-1);
109 r_sort_b(a, ta, n, 0, tr, endch); 109 r_sort_b(a, ta, n, 0, tr, endch);
110 free(ta); 110 free(ta);