summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormiod <>2015-02-11 06:40:04 +0000
committermiod <>2015-02-11 06:40:04 +0000
commit01fabf00f34c0ca7466352b13f7071a4170301fc (patch)
tree470f3b7cf86d73904926240149bf79bf91d98e75
parent74b6aedb7d6d115e1fa81e96806190a780392341 (diff)
downloadopenbsd-01fabf00f34c0ca7466352b13f7071a4170301fc.tar.gz
openbsd-01fabf00f34c0ca7466352b13f7071a4170301fc.tar.bz2
openbsd-01fabf00f34c0ca7466352b13f7071a4170301fc.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--src/regress/lib/libcrypto/gcm128/gcm128test.c16
1 files 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)
857{ 857{
858 GCM128_CONTEXT ctx; 858 GCM128_CONTEXT ctx;
859 AES_KEY key; 859 AES_KEY key;
860 uint8_t *out; 860 uint8_t *out = NULL;
861 size_t out_len; 861 size_t out_len;
862 int ret = 1; 862 int ret = 1;
863 863
864 out_len = tv->P_len; 864 out_len = tv->P_len;
865 out = malloc(out_len); 865 if (out_len != 0) {
866 if (out == NULL) 866 out = malloc(out_len);
867 err(1, "malloc"); 867 if (out == NULL)
868 err(1, "malloc");
869 }
868 870
869 AES_set_encrypt_key(tv->K, tv->K_len * 8, &key); 871 AES_set_encrypt_key(tv->K, tv->K_len * 8, &key);
870 872
871 memset(out, 0, out_len); 873 if (out_len != 0)
874 memset(out, 0, out_len);
872 CRYPTO_gcm128_init(&ctx, &key, (block128_f)AES_encrypt); 875 CRYPTO_gcm128_init(&ctx, &key, (block128_f)AES_encrypt);
873 CRYPTO_gcm128_setiv(&ctx, tv->IV, tv->IV_len); 876 CRYPTO_gcm128_setiv(&ctx, tv->IV, tv->IV_len);
874 if (tv->A_len > 0) 877 if (tv->A_len > 0)
@@ -885,7 +888,8 @@ do_gcm128_test(int test_no, struct gcm128_test *tv)
885 goto fail; 888 goto fail;
886 } 889 }
887 890
888 memset(out, 0, out_len); 891 if (out_len != 0)
892 memset(out, 0, out_len);
889 CRYPTO_gcm128_setiv(&ctx, tv->IV, tv->IV_len); 893 CRYPTO_gcm128_setiv(&ctx, tv->IV, tv->IV_len);
890 if (tv->A_len > 0) 894 if (tv->A_len > 0)
891 CRYPTO_gcm128_aad(&ctx, tv->A, tv->A_len); 895 CRYPTO_gcm128_aad(&ctx, tv->A, tv->A_len);