summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorderaadt <>2002-07-30 00:11:07 +0000
committerderaadt <>2002-07-30 00:11:07 +0000
commit4eb350f99f2e7e654669cca4a9c1cce8e0d77e9e (patch)
treeb8bdbf09d675acc0f5c192733b4351bb651caa0f /src
parent647ec2253a1bdb04c0e60e9d5c78159c7df3fad8 (diff)
downloadopenbsd-4eb350f99f2e7e654669cca4a9c1cce8e0d77e9e.tar.gz
openbsd-4eb350f99f2e7e654669cca4a9c1cce8e0d77e9e.tar.bz2
openbsd-4eb350f99f2e7e654669cca4a9c1cce8e0d77e9e.zip
return failure if integer overflow happens. sigh; too people had to
help get this right.
Diffstat (limited to 'src')
-rw-r--r--src/lib/libc/stdlib/calloc.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/lib/libc/stdlib/calloc.c b/src/lib/libc/stdlib/calloc.c
index e79d71f93e..c53b22b431 100644
--- a/src/lib/libc/stdlib/calloc.c
+++ b/src/lib/libc/stdlib/calloc.c
@@ -32,11 +32,13 @@
32 */ 32 */
33 33
34#if defined(LIBC_SCCS) && !defined(lint) 34#if defined(LIBC_SCCS) && !defined(lint)
35static char *rcsid = "$OpenBSD: calloc.c,v 1.5 1999/11/10 20:12:31 millert Exp $"; 35static char *rcsid = "$OpenBSD: calloc.c,v 1.6 2002/07/30 00:11:07 deraadt Exp $";
36#endif /* LIBC_SCCS and not lint */ 36#endif /* LIBC_SCCS and not lint */
37 37
38#include <stdlib.h> 38#include <stdlib.h>
39#include <string.h> 39#include <string.h>
40#include <limits.h>
41#include <errno.h>
40 42
41void * 43void *
42calloc(num, size) 44calloc(num, size)
@@ -45,6 +47,10 @@ calloc(num, size)
45{ 47{
46 register void *p; 48 register void *p;
47 49
50 if (SIZE_T_MAX / num < size) {
51 errno = ENOMEM;
52 return NULL;
53 }
48 size *= num; 54 size *= num;
49 p = malloc(size); 55 p = malloc(size);
50 if (p) 56 if (p)