Browse Source

use calloc() to avoid malloc(n * m) overflows; checked by djm canacar jsg

OPENBSD_4_3
deraadt 17 years ago
parent
commit
93a9caecd5
3 changed files with 6 additions and 6 deletions
  1. +2
    -2
      src/lib/libc/stdlib/hcreate.c
  2. +2
    -2
      src/lib/libc/stdlib/radixsort.c
  3. +2
    -2
      src/lib/libc/string/bm.c

+ 2
- 2
src/lib/libc/stdlib/hcreate.c View File

@ -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 $ */ /* $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. */ /* Allocate the table. */
htablesize = nel; htablesize = nel;
htable = malloc(htablesize * sizeof htable[0]);
htable = calloc(htablesize, sizeof htable[0]);
if (htable == NULL) { if (htable == NULL) {
errno = ENOMEM; errno = ENOMEM;
return 0; return 0;


+ 2
- 2
src/lib/libc/stdlib/radixsort.c View File

@ -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 * Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved. * 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) if (n < THRESHOLD)
simplesort(a, n, 0, tr, endch); simplesort(a, n, 0, tr, endch);
else { else {
if ((ta = malloc(n * sizeof(a))) == NULL)
if ((ta = calloc(n, sizeof(a))) == NULL)
return (-1); return (-1);
r_sort_b(a, ta, n, 0, tr, endch); r_sort_b(a, ta, n, 0, tr, endch);
free(ta); free(ta);


+ 2
- 2
src/lib/libc/string/bm.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: bm.c,v 1.6 2005/08/08 08:05:37 espie Exp $ */
/* $OpenBSD: bm.c,v 1.7 2007/09/02 15:19:18 deraadt Exp $ */
/*- /*-
* Copyright (c) 1994 * Copyright (c) 1994
* The Regents of the University of California. All rights reserved. * The Regents of the University of California. All rights reserved.
@ -104,7 +104,7 @@ bm_comp(u_char const *pb, size_t len, u_char const *freq)
goto mem; goto mem;
memcpy(pat->pat, pb, pat->patlen); memcpy(pat->pat, pb, pat->patlen);
/* get skip delta */ /* get skip delta */
if ((pat->delta = malloc(256 * sizeof(*d))) == NULL)
if ((pat->delta = calloc(256, sizeof(*d))) == NULL)
goto mem; goto mem;
for (j = 0, d = pat->delta; j < 256; j++) for (j = 0, d = pat->delta; j < 256; j++)
d[j] = pat->patlen; d[j] = pat->patlen;


Loading…
Cancel
Save