diff options
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | xmalloc.c | 10 |
2 files changed, 13 insertions, 6 deletions
@@ -1,3 +1,10 @@ | |||
1 | 20060331 | ||
2 | - OpenBSD CVS Sync | ||
3 | - deraadt@cvs.openbsd.org 2006/03/27 01:21:18 | ||
4 | [xmalloc.c] | ||
5 | we can do the size & nmemb check before the integer overflow check; | ||
6 | evol | ||
7 | |||
1 | 20060326 | 8 | 20060326 |
2 | - OpenBSD CVS Sync | 9 | - OpenBSD CVS Sync |
3 | - jakob@cvs.openbsd.org 2006/03/15 08:46:44 | 10 | - jakob@cvs.openbsd.org 2006/03/15 08:46:44 |
@@ -4446,4 +4453,4 @@ | |||
4446 | - (djm) Trim deprecated options from INSTALL. Mention UsePAM | 4453 | - (djm) Trim deprecated options from INSTALL. Mention UsePAM |
4447 | - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu | 4454 | - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu |
4448 | 4455 | ||
4449 | $Id: ChangeLog,v 1.4287 2006/03/26 03:30:33 djm Exp $ | 4456 | $Id: ChangeLog,v 1.4288 2006/03/31 12:09:17 djm Exp $ |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: xmalloc.c,v 1.20 2006/03/25 13:17:03 djm Exp $ */ | 1 | /* $OpenBSD: xmalloc.c,v 1.21 2006/03/27 01:21:18 deraadt Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -36,10 +36,10 @@ xcalloc(size_t nmemb, size_t size) | |||
36 | { | 36 | { |
37 | void *ptr; | 37 | void *ptr; |
38 | 38 | ||
39 | if (nmemb && size && SIZE_T_MAX / nmemb < size) | ||
40 | fatal("xcalloc: nmemb * size > SIZE_T_MAX"); | ||
41 | if (size == 0 || nmemb == 0) | 39 | if (size == 0 || nmemb == 0) |
42 | fatal("xcalloc: zero size"); | 40 | fatal("xcalloc: zero size"); |
41 | if (SIZE_T_MAX / nmemb < size) | ||
42 | fatal("xcalloc: nmemb * size > SIZE_T_MAX"); | ||
43 | ptr = calloc(nmemb, size); | 43 | ptr = calloc(nmemb, size); |
44 | if (ptr == NULL) | 44 | if (ptr == NULL) |
45 | fatal("xcalloc: out of memory (allocating %lu bytes)", | 45 | fatal("xcalloc: out of memory (allocating %lu bytes)", |
@@ -53,10 +53,10 @@ xrealloc(void *ptr, size_t nmemb, size_t size) | |||
53 | void *new_ptr; | 53 | void *new_ptr; |
54 | size_t new_size = nmemb * size; | 54 | size_t new_size = nmemb * size; |
55 | 55 | ||
56 | if (nmemb && size && SIZE_T_MAX / nmemb < size) | ||
57 | fatal("xrealloc: nmemb * size > SIZE_T_MAX"); | ||
58 | if (new_size == 0) | 56 | if (new_size == 0) |
59 | fatal("xrealloc: zero size"); | 57 | fatal("xrealloc: zero size"); |
58 | if (SIZE_T_MAX / nmemb < size) | ||
59 | fatal("xrealloc: nmemb * size > SIZE_T_MAX"); | ||
60 | if (ptr == NULL) | 60 | if (ptr == NULL) |
61 | new_ptr = malloc(new_size); | 61 | new_ptr = malloc(new_size); |
62 | else | 62 | else |