diff options
| author | miod <> | 2015-02-11 06:40:04 +0000 |
|---|---|---|
| committer | miod <> | 2015-02-11 06:40:04 +0000 |
| commit | a958e8104030c4eac21e785de5482ac58facc7c8 (patch) | |
| tree | 470f3b7cf86d73904926240149bf79bf91d98e75 | |
| parent | 3fb89787679dd239a55ca0a4e366ad4e2051fe84 (diff) | |
| download | openbsd-a958e8104030c4eac21e785de5482ac58facc7c8.tar.gz openbsd-a958e8104030c4eac21e785de5482ac58facc7c8.tar.bz2 openbsd-a958e8104030c4eac21e785de5482ac58facc7c8.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
Diffstat (limited to '')
| -rw-r--r-- | src/regress/lib/libcrypto/gcm128/gcm128test.c | 16 |
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); |
