From: Pauli Date: Sun, 20 Jun 2021 02:40:48 +0000 (+1000) Subject: testutil: preserve app_malloc()'s failure behaviour X-Git-Tag: openssl-3.0.0-beta2~255 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f31bbeff048056874fcc4e6b33ffb847369f65c5;p=thirdparty%2Fopenssl.git testutil: preserve app_malloc()'s failure behaviour app_malloc() terminates execution if the allocation fails. The tests implement their own app_malloc() in an attempt to reduce the amount of code pulled in. This version also needs to terminate on failed allocation. The alternative would be adding failed allocation checks pervasively throughout the apps's commands. Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/15836) --- diff --git a/test/testutil/apps_mem.c b/test/testutil/apps_mem.c index 437bd89c59c..ef5e266b250 100644 --- a/test/testutil/apps_mem.c +++ b/test/testutil/apps_mem.c @@ -7,13 +7,24 @@ * https://www.openssl.org/source/license.html */ +#include #include "apps.h" +#include "../testutil.h" /* shim that avoids sucking in too much from apps/apps.c */ void *app_malloc(size_t sz, const char *what) { - void *vp = OPENSSL_malloc(sz); + void *vp; + /* + * This isn't ideal but it is what the app's app_malloc() does on failure. + * Instead of exiting with a failure, abort() is called which makes sure + * that there will be a good stack trace for debugging purposes. + */ + if (!TEST_ptr(vp = OPENSSL_malloc(sz))) { + TEST_info("Could not allocate %zu bytes for %s\n", sz, what); + abort(); + } return vp; }