summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormiod <miod@openbsd.org>2015-02-11 06:40:04 +0000
committermiod <miod@openbsd.org>2015-02-11 06:40:04 +0000
commit2172a86ffec0ade377c9f24d6c8bc03756d10c9c (patch)
treecd3ac45093cd226ec70dcb875c709d25a3bc2a78
parentthis doesnt need lockmgr. we dont need sys/lock.h (diff)
downloadwireguard-openbsd-2172a86ffec0ade377c9f24d6c8bc03756d10c9c.tar.xz
wireguard-openbsd-2172a86ffec0ade377c9f24d6c8bc03756d10c9c.zip
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
-rw-r--r--regress/lib/libcrypto/gcm128/gcm128test.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/regress/lib/libcrypto/gcm128/gcm128test.c b/regress/lib/libcrypto/gcm128/gcm128test.c
index ed78366e3ca..cf52d1fd324 100644
--- a/regress/lib/libcrypto/gcm128/gcm128test.c
+++ b/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);