From: Bernd Edlinger Date: Mon, 18 Aug 2025 09:39:52 +0000 (+0200) Subject: Fix the return value of OBJ_create X-Git-Tag: openssl-3.6.0-alpha1~95 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5e34d6476016db7630aed77e927d95dd94fc67b0;p=thirdparty%2Fopenssl.git Fix the return value of OBJ_create OBJ_create is supposed to return NID_undef on error and the newly created NID on success. Fixes: 88a1fbb8d1b2 ("reduce lock contention when adding objects to ADDED_OBJ hash table") Reviewed-by: Neil Horman Reviewed-by: Tomas Mraz Reviewed-by: Matt Caswell Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/28293) --- diff --git a/crypto/objects/obj_dat.c b/crypto/objects/obj_dat.c index e331b73b500..8c3b8db8c67 100644 --- a/crypto/objects/obj_dat.c +++ b/crypto/objects/obj_dat.c @@ -686,32 +686,32 @@ int OBJ_create_objects(BIO *in) int OBJ_create(const char *oid, const char *sn, const char *ln) { ASN1_OBJECT *tmpoid = NULL; - int ok = 0; + int ok = NID_undef; /* With no arguments at all, nothing can be done */ if (oid == NULL && sn == NULL && ln == NULL) { ERR_raise(ERR_LIB_OBJ, ERR_R_PASSED_INVALID_ARGUMENT); - return 0; + return NID_undef; } /* Check to see if short or long name already present */ if ((sn != NULL && OBJ_sn2nid(sn) != NID_undef) || (ln != NULL && OBJ_ln2nid(ln) != NID_undef)) { ERR_raise(ERR_LIB_OBJ, OBJ_R_OID_EXISTS); - return 0; + return NID_undef; } if (oid != NULL) { /* Convert numerical OID string to an ASN1_OBJECT structure */ tmpoid = OBJ_txt2obj(oid, 1); if (tmpoid == NULL) - return 0; + return NID_undef; } else { /* Create a no-OID ASN1_OBJECT */ tmpoid = ASN1_OBJECT_new(); if (tmpoid == NULL) { ERR_raise(ERR_LIB_OBJ, ERR_R_ASN1_LIB); - return 0; + return NID_undef; } } @@ -730,9 +730,7 @@ int OBJ_create(const char *oid, const char *sn, const char *ln) tmpoid->sn = (char *)sn; tmpoid->ln = (char *)ln; - if (OBJ_add_object(tmpoid) != NID_undef) - ok = 1; - + ok = OBJ_add_object(tmpoid); tmpoid->sn = NULL; tmpoid->ln = NULL; diff --git a/test/evp_extra_test.c b/test/evp_extra_test.c index 7ca72d71f93..6f1e4b57823 100644 --- a/test/evp_extra_test.c +++ b/test/evp_extra_test.c @@ -5798,6 +5798,8 @@ static int test_custom_md_meth(void) nid = OBJ_create("1.3.6.1.4.1.16604.998866.1", "custom-md", "custom-md"); if (!TEST_int_ne(nid, NID_undef)) goto err; + if (!TEST_int_eq(OBJ_txt2nid("1.3.6.1.4.1.16604.998866.1"), nid)) + goto err; tmp = EVP_MD_meth_new(nid, NID_undef); if (!TEST_ptr(tmp)) goto err; @@ -5893,6 +5895,8 @@ static int test_custom_ciph_meth(void) nid = OBJ_create("1.3.6.1.4.1.16604.998866.2", "custom-ciph", "custom-ciph"); if (!TEST_int_ne(nid, NID_undef)) goto err; + if (!TEST_int_eq(OBJ_txt2nid("1.3.6.1.4.1.16604.998866.2"), nid)) + goto err; tmp = EVP_CIPHER_meth_new(nid, 16, 16); if (!TEST_ptr(tmp)) goto err;