summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorShane Lontis <shane.lontis@oracle.com>2021-04-21 13:49:29 +1000
committerRichard Levitte <levitte@openssl.org>2021-04-27 12:43:52 +0200
commite466dc3646bc15fa928366a2c64ed987daab5b2c (patch)
treeeb4db326d9dd9b3d11a449e2f3a0c5b4ee8f4cf6 /test
parent1727465471e800548694da96b8970743b7efa7ff (diff)
Test that we don't have a memory leak in d2i_ASN1_OBJECT.
Fixes #14667 Reworked test supplied by @smcpeak into a unit test. Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/14938) (cherry picked from commit 7c65179ad95d0f6f598ee82e763fce2567fe5802)
Diffstat (limited to 'test')
-rw-r--r--test/asn1_decode_test.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/asn1_decode_test.c b/test/asn1_decode_test.c
index c6e1501fa1..3a3ad525ae 100644
--- a/test/asn1_decode_test.c
+++ b/test/asn1_decode_test.c
@@ -12,6 +12,7 @@
#include <openssl/rand.h>
#include <openssl/asn1t.h>
+#include <openssl/obj_mac.h>
#include "internal/numbers.h"
#include "testutil.h"
@@ -195,6 +196,30 @@ static int test_invalid_template(void)
return 0;
}
+static int test_reuse_asn1_object(void)
+{
+ static unsigned char cn_der[] = { 0x06, 0x03, 0x55, 0x04, 0x06 };
+ static unsigned char oid_der[] = {
+ 0x06, 0x06, 0x2a, 0x03, 0x04, 0x05, 0x06, 0x07
+ };
+ int ret = 0;
+ ASN1_OBJECT *obj;
+ unsigned char const *p = oid_der;
+
+ /* Create an object that owns dynamically allocated 'sn' and 'ln' fields */
+
+ if (!TEST_ptr(obj = ASN1_OBJECT_create(NID_undef, cn_der, sizeof(cn_der),
+ "C", "countryName")))
+ goto err;
+ /* reuse obj - this should not leak sn and ln */
+ if (!TEST_ptr(d2i_ASN1_OBJECT(&obj, &p, sizeof(oid_der))))
+ goto err;
+ ret = 1;
+err:
+ ASN1_OBJECT_free(obj);
+ return ret;
+}
+
int setup_tests(void)
{
#ifndef OPENSSL_NO_DEPRECATED_3_0
@@ -205,5 +230,6 @@ int setup_tests(void)
ADD_TEST(test_int64);
ADD_TEST(test_uint64);
ADD_TEST(test_invalid_template);
+ ADD_TEST(test_reuse_asn1_object);
return 1;
}