From: Christian Heller Date: Thu, 20 Nov 2014 23:29:55 +0000 (+0100) Subject: Client: Add size test to array_append(). X-Git-Tag: tce~582 X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/%7B%7Bprefix%7D%7D/%7Broute%7D?a=commitdiff_plain;h=39a27d187278fc2d0cc05ef2ad59a872c4f19b2b;p=plomrogue Client: Add size test to array_append(). --- diff --git a/src/client/array_append.c b/src/client/array_append.c index b2bbab9..52bcf97 100644 --- a/src/client/array_append.c +++ b/src/client/array_append.c @@ -7,9 +7,10 @@ #include "array_append.h" #include /* size_t */ -#include /* uint32_t */ +#include /* uint32_t, UINT32_MAX */ #include /* free() */ #include /* memcpy() */ +#include "../common/rexit.h" /* exit_trouble() */ #include "../common/try_malloc.h" /* try_malloc() */ @@ -17,12 +18,12 @@ extern void array_append(uint32_t old_n, size_t region_size, void * new_region, void ** ptr_old_array) { + exit_trouble(UINT32_MAX<(old_n+1)*region_size, __func__, "too large sizes"); uint32_t old_size = old_n * region_size; uint32_t new_size = old_size + region_size; char * new_array = try_malloc(new_size, __func__); memcpy(new_array, * ptr_old_array, old_size); memcpy(new_array + (old_n * region_size), new_region, region_size); free(* ptr_old_array); - * ptr_old_array = new_array; + *ptr_old_array = new_array; } -