From c4641c1dc73700968ee90de85e04b2f32fbadc8a Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Wed, 23 Apr 2014 21:06:41 +0000 Subject: Audit malloc(3)/calloc(3)/realloc(3) usage. * Change eight reallocs to reallocarray to be safe from overflows. * Change one malloc to reallocarray to be safe from overflows. * Change one calloc to reallocarray, no zeroing needed. * Change the order of arguments of three callocs (aesthetical). --- mandoc_aux.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'mandoc_aux.c') diff --git a/mandoc_aux.c b/mandoc_aux.c index 25666a27..a4cb3c19 100644 --- a/mandoc_aux.c +++ b/mandoc_aux.c @@ -1,4 +1,4 @@ -/* $Id: mandoc_aux.c,v 1.1 2014/03/23 11:59:17 schwarze Exp $ */ +/* $Id: mandoc_aux.c,v 1.2 2014/04/23 21:06:41 schwarze Exp $ */ /* * Copyright (c) 2009, 2011 Kristaps Dzonsons * Copyright (c) 2014 Ingo Schwarze @@ -80,6 +80,18 @@ mandoc_realloc(void *ptr, size_t size) return(ptr); } +void * +mandoc_reallocarray(void *ptr, size_t num, size_t size) +{ + + ptr = reallocarray(ptr, num, size); + if (NULL == ptr) { + perror(NULL); + exit((int)MANDOCLEVEL_SYSERR); + } + return(ptr); +} + char * mandoc_strdup(const char *ptr) { -- cgit v1.2.3