summaryrefslogtreecommitdiffstats
path: root/test/evp_test.c
diff options
context:
space:
mode:
authorFdaSilvaYY <fdasilvayy@gmail.com>2019-01-08 16:27:27 +1000
committerPauli <paul.dale@oracle.com>2019-01-08 16:30:01 +1000
commit37cad7e65641e83d9f92b47fd0e34ea2d8c3b277 (patch)
tree2ec6586e1770187a3222227917a57e8d20cbc5c2 /test/evp_test.c
parent25eb9299cec4404a4cdf3167056bd147af2582f3 (diff)
Fix CID 1434549: Unchecked return value in test/evp_test.c
5. check_return: Calling EVP_EncodeUpdate without checking return value (as is done elsewhere 4 out of 5 times). Fix CID 1371695, 1371698: Resource leak in test/evp_test.c - leaked_storage: Variable edata going out of scope leaks the storage it points to. - leaked_storage: Variable encode_ctx going out of scope leaks the storage it points to Fix CID 1430437, 1430426, 1430429 : Dereference before null check in test/drbg_cavs_test.c check_after_deref: Null-checking drbg suggests that it may be null, but it has already been dereferenced on all paths leading to the check Fix CID 1440765: Dereference before null check in test/ssltestlib.c check_after_deref: Null-checking ctx suggests that it may be null, but it has already been dereferenced on all paths leading to the check. Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Paul Dale <paul.dale@oracle.com> Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com> Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de> (Merged from https://github.com/openssl/openssl/pull/7993) (cherry picked from commit 760e2d60e62511a6fb96f547f6730d05eb5f47ec)
Diffstat (limited to 'test/evp_test.c')
-rw-r--r--test/evp_test.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/test/evp_test.c b/test/evp_test.c
index e7e376e657..85c1552a7a 100644
--- a/test/evp_test.c
+++ b/test/evp_test.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2015-2019 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
@@ -1559,15 +1559,18 @@ static int encode_test_init(EVP_TEST *t, const char *encoding)
} else if (strcmp(encoding, "invalid") == 0) {
edata->encoding = BASE64_INVALID_ENCODING;
if (!TEST_ptr(t->expected_err = OPENSSL_strdup("DECODE_ERROR")))
- return 0;
+ goto err;
} else {
TEST_error("Bad encoding: %s."
" Should be one of {canonical, valid, invalid}",
encoding);
- return 0;
+ goto err;
}
t->data = edata;
return 1;
+err:
+ OPENSSL_free(edata);
+ return 0;
}
static void encode_test_cleanup(EVP_TEST *t)
@@ -1596,7 +1599,7 @@ static int encode_test_run(EVP_TEST *t)
ENCODE_DATA *expected = t->data;
unsigned char *encode_out = NULL, *decode_out = NULL;
int output_len, chunk_len;
- EVP_ENCODE_CTX *decode_ctx;
+ EVP_ENCODE_CTX *decode_ctx = NULL, *encode_ctx = NULL;
if (!TEST_ptr(decode_ctx = EVP_ENCODE_CTX_new())) {
t->err = "INTERNAL_ERROR";
@@ -1604,7 +1607,6 @@ static int encode_test_run(EVP_TEST *t)
}
if (expected->encoding == BASE64_CANONICAL_ENCODING) {
- EVP_ENCODE_CTX *encode_ctx;
if (!TEST_ptr(encode_ctx = EVP_ENCODE_CTX_new())
|| !TEST_ptr(encode_out =
@@ -1612,15 +1614,15 @@ static int encode_test_run(EVP_TEST *t)
goto err;
EVP_EncodeInit(encode_ctx);
- EVP_EncodeUpdate(encode_ctx, encode_out, &chunk_len,
- expected->input, expected->input_len);
+ if (!TEST_true(EVP_EncodeUpdate(encode_ctx, encode_out, &chunk_len,
+ expected->input, expected->input_len)))
+ goto err;
+
output_len = chunk_len;
EVP_EncodeFinal(encode_ctx, encode_out + chunk_len, &chunk_len);
output_len += chunk_len;
- EVP_ENCODE_CTX_free(encode_ctx);
-
if (!memory_err_compare(t, "BAD_ENCODING",
expected->output, expected->output_len,
encode_out, output_len))
@@ -1658,6 +1660,7 @@ static int encode_test_run(EVP_TEST *t)
OPENSSL_free(encode_out);
OPENSSL_free(decode_out);
EVP_ENCODE_CTX_free(decode_ctx);
+ EVP_ENCODE_CTX_free(encode_ctx);
return 1;
}