summaryrefslogtreecommitdiffstats
path: root/test/evp_extra_test.c
diff options
context:
space:
mode:
authorBernd Edlinger <bernd.edlinger@hotmail.de>2023-10-27 12:05:05 +0200
committerTomas Mraz <tomas@openssl.org>2024-08-21 15:53:37 +0200
commite91384d5b0547bf797e2b44976f142d146c4e650 (patch)
tree07159a2883660ed3d641203ab2eeea09032b23bf /test/evp_extra_test.c
parentx_attrib: fix a memory leak (diff)
downloadopenssl-e91384d5b0547bf797e2b44976f142d146c4e650.tar.xz
openssl-e91384d5b0547bf797e2b44976f142d146c4e650.zip
Fix error handling in OBJ_add_object
This fixes the possible memory leak in OBJ_add_object when a pre-existing object is replaced by a new one, with identical NID, OID, and/or short/long name. We do not try to delete any orphans, but only mark them as type == -1, because the previously returned pointers from OBJ_nid2obj/OBJ_nid2sn/OBJ_nid2ln may be cached by applications and can thus not be cleaned up before the application terminates. Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/22534)
Diffstat (limited to 'test/evp_extra_test.c')
-rw-r--r--test/evp_extra_test.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/test/evp_extra_test.c b/test/evp_extra_test.c
index 1b9b440d8c..af19b45239 100644
--- a/test/evp_extra_test.c
+++ b/test/evp_extra_test.c
@@ -4944,6 +4944,7 @@ static int custom_md_cleanup(EVP_MD_CTX *ctx)
static int test_custom_md_meth(void)
{
+ ASN1_OBJECT *o = NULL;
EVP_MD_CTX *mdctx = NULL;
EVP_MD *tmp = NULL;
char mess[] = "Test Message\n";
@@ -4989,8 +4990,21 @@ static int test_custom_md_meth(void)
|| !TEST_int_eq(custom_md_cleanup_called, 1))
goto err;
+ if (!TEST_int_eq(OBJ_create("1.3.6.1.4.1.16604.998866.1",
+ "custom-md", "custom-md"), NID_undef)
+ || !TEST_int_eq(ERR_GET_LIB(ERR_peek_error()), ERR_LIB_OBJ)
+ || !TEST_int_eq(ERR_GET_REASON(ERR_get_error()), OBJ_R_OID_EXISTS))
+ goto err;
+
+ o = ASN1_OBJECT_create(nid, (unsigned char *)
+ "\53\6\1\4\1\201\201\134\274\373\122\1", 12,
+ "custom-md", "custom-md");
+ if (!TEST_int_eq(OBJ_add_object(o), nid))
+ goto err;
+
testresult = 1;
err:
+ ASN1_OBJECT_free(o);
EVP_MD_CTX_free(mdctx);
EVP_MD_meth_free(tmp);
return testresult;