From 01fabf00f34c0ca7466352b13f7071a4170301fc Mon Sep 17 00:00:00 2001 From: miod <> Date: Wed, 11 Feb 2015 06:40:04 +0000 Subject: Do not rely upon malloc(0) not returning NULL. Not all malloc implementations have this property. Instead, skip the malloc and memcmp if their size is zero. Per bcook@ request in order to run on AIX --- src/regress/lib/libcrypto/gcm128/gcm128test.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/regress/lib/libcrypto/gcm128/gcm128test.c b/src/regress/lib/libcrypto/gcm128/gcm128test.c index ed78366e3c..cf52d1fd32 100644 --- a/src/regress/lib/libcrypto/gcm128/gcm128test.c +++ b/src/regress/lib/libcrypto/gcm128/gcm128test.c @@ -857,18 +857,21 @@ do_gcm128_test(int test_no, struct gcm128_test *tv) { GCM128_CONTEXT ctx; AES_KEY key; - uint8_t *out; + uint8_t *out = NULL; size_t out_len; int ret = 1; out_len = tv->P_len; - out = malloc(out_len); - if (out == NULL) - err(1, "malloc"); + if (out_len != 0) { + out = malloc(out_len); + if (out == NULL) + err(1, "malloc"); + } AES_set_encrypt_key(tv->K, tv->K_len * 8, &key); - memset(out, 0, out_len); + if (out_len != 0) + memset(out, 0, out_len); CRYPTO_gcm128_init(&ctx, &key, (block128_f)AES_encrypt); CRYPTO_gcm128_setiv(&ctx, tv->IV, tv->IV_len); if (tv->A_len > 0) @@ -885,7 +888,8 @@ do_gcm128_test(int test_no, struct gcm128_test *tv) goto fail; } - memset(out, 0, out_len); + if (out_len != 0) + memset(out, 0, out_len); CRYPTO_gcm128_setiv(&ctx, tv->IV, tv->IV_len); if (tv->A_len > 0) CRYPTO_gcm128_aad(&ctx, tv->A, tv->A_len); -- cgit v1.2.3-55-g6feb