summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib/calloc.c
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2002-07-30 00:11:07 +0000
committerderaadt <deraadt@openbsd.org>2002-07-30 00:11:07 +0000
commitc7b2af4b3f7e78424f8943119b1397773e619e77 (patch)
tree38294799a1227165fcff233aec619683b1ced7a2 /lib/libc/stdlib/calloc.c
parentswitch to ether_input_mbuf(); mickey@ tested and ok. (diff)
downloadwireguard-openbsd-c7b2af4b3f7e78424f8943119b1397773e619e77.tar.xz
wireguard-openbsd-c7b2af4b3f7e78424f8943119b1397773e619e77.zip
return failure if integer overflow happens. sigh; too people had to
help get this right.
Diffstat (limited to 'lib/libc/stdlib/calloc.c')
-rw-r--r--lib/libc/stdlib/calloc.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/libc/stdlib/calloc.c b/lib/libc/stdlib/calloc.c
index e79d71f93e2..c53b22b4310 100644
--- a/lib/libc/stdlib/calloc.c
+++ b/lib/libc/stdlib/calloc.c
@@ -32,11 +32,13 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: calloc.c,v 1.5 1999/11/10 20:12:31 millert Exp $";
+static char *rcsid = "$OpenBSD: calloc.c,v 1.6 2002/07/30 00:11:07 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdlib.h>
#include <string.h>
+#include <limits.h>
+#include <errno.h>
void *
calloc(num, size)
@@ -45,6 +47,10 @@ calloc(num, size)
{
register void *p;
+ if (SIZE_T_MAX / num < size) {
+ errno = ENOMEM;
+ return NULL;
+ }
size *= num;
p = malloc(size);
if (p)