From 46b0ace509d9ed013915e9ab8013c7c712e11395 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 24 Jun 2014 19:06:05 +0200 Subject: xmalloc: Add and use xcalloc Add a wrapper for calloc which checks for integer overflows in the calculation of the size to allocate. Use xcalloc to allocate an array of objects instead of calculating the size ourselves, which might cause an integer overflow. Signed-off-by: Tobias Klauser --- curvetun_server.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'curvetun_server.c') diff --git a/curvetun_server.c b/curvetun_server.c index 36a55fe..c1d5477 100644 --- a/curvetun_server.c +++ b/curvetun_server.c @@ -638,7 +638,7 @@ int server_main(char *home, char *dev, char *port, int udp, int ipv4, int log) set_nonblocking(lfd); - events = xzmalloc(MAX_EPOLL_SIZE * sizeof(*events)); + events = xcalloc(MAX_EPOLL_SIZE, sizeof(*events)); for (i = 0; i < MAX_EPOLL_SIZE; ++i) events[i].data.fd = -1; @@ -661,7 +661,7 @@ int server_main(char *home, char *dev, char *port, int udp, int ipv4, int log) if (!ispow2(threads)) syslog_panic("Thread number not power of two!\n"); - threadpool = xzmalloc(sizeof(*threadpool) * threads); + threadpool = xcalloc(threads, sizeof(*threadpool)); thread_spawn_or_panic(cpus, efd[1], refd[1], tunfd, ipv4, udp); init_cpusched(threads); -- cgit v1.2.3-54-g00ecf