]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix the return value of OBJ_create
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Mon, 18 Aug 2025 09:39:52 +0000 (11:39 +0200)
committerNeil Horman <nhorman@openssl.org>
Tue, 19 Aug 2025 13:20:04 +0000 (09:20 -0400)
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 <nhorman@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/28293)

crypto/objects/obj_dat.c
test/evp_extra_test.c

index e331b73b500122dc3bbd39250e2cf9f36c8c16df..8c3b8db8c677cfa57da31a5e083874a7d2a93c3f 100644 (file)
@@ -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;
index 7ca72d71f933217ac7105d41430d2f8e7b92e06a..6f1e4b57823ea08abb9fe0488967cc116154b379 100644 (file)
@@ -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;