summaryrefslogtreecommitdiff
path: root/src/lib/libc
diff options
context:
space:
mode:
authormiod <>2002-07-30 07:31:20 +0000
committermiod <>2002-07-30 07:31:20 +0000
commitb71da00fbd6b792933203df71a2d63c20c8e9d98 (patch)
tree6f3c82e026fe6ab3d33b546d5f925c439b66e5c3 /src/lib/libc
parentb88d7a5cb2b7d6387d1028751a707f2097b0269c (diff)
downloadopenbsd-b71da00fbd6b792933203df71a2d63c20c8e9d98.tar.gz
openbsd-b71da00fbd6b792933203df71a2d63c20c8e9d98.tar.bz2
openbsd-b71da00fbd6b792933203df71a2d63c20c8e9d98.zip
MFC (deraadt):
return failure if integer overflow happens. sigh; too people had to help get this right.
Diffstat (limited to 'src/lib/libc')
-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..a9e49e39ad 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.5.8.1 2002/07/30 07:31:20 miod 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)