]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix potential UB memcmps in obj_dat.c
authorBob Beck <beck@openssl.org>
Thu, 30 Apr 2026 19:27:32 +0000 (13:27 -0600)
committerNeil Horman <nhorman@openssl.org>
Thu, 7 May 2026 18:14:45 +0000 (14:14 -0400)
By calling the real OBJ_cmp

Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
MergeDate: Thu May  7 18:14:54 2026
(Merged from https://github.com/openssl/openssl/pull/31048)

crypto/objects/obj_dat.c

index e30ce1c462b635acb30dab44a91c60c990a16a84..8bb029ac32e84d517d865df1d545831960db0ec7 100644 (file)
@@ -162,8 +162,7 @@ static unsigned long added_obj_hash(const ADDED_OBJ *ca)
  */
 static int obj_equivalent(const ASN1_OBJECT *a, const ASN1_OBJECT *b)
 {
-    return a->length == b->length
-        && memcmp(a->data, b->data, (size_t)a->length) == 0
+    return OBJ_cmp(a, b) == 0
         && (a->sn == NULL) == (b->sn == NULL)
         && strcmp(a->sn ? a->sn : "", b->sn ? b->sn : "") == 0
         && (a->ln == NULL) == (b->ln == NULL)
@@ -182,10 +181,7 @@ static int added_obj_cmp(const ADDED_OBJ *ca, const ADDED_OBJ *cb)
     b = cb->obj;
     switch (ca->type) {
     case ADDED_DATA:
-        i = (a->length - b->length);
-        if (i)
-            return i;
-        return memcmp(a->data, b->data, (size_t)a->length);
+        return OBJ_cmp(a, b);
     case ADDED_SNAME:
         if (a->sn == NULL)
             return -1;
@@ -296,16 +292,7 @@ const char *OBJ_nid2ln(int n)
 
 static int obj_cmp(const ASN1_OBJECT *const *ap, const unsigned int *bp)
 {
-    int j;
-    const ASN1_OBJECT *a = *ap;
-    const ASN1_OBJECT *b = &nid_objs[*bp];
-
-    j = (a->length - b->length);
-    if (j)
-        return j;
-    if (a->length == 0)
-        return 0;
-    return memcmp(a->data, b->data, a->length);
+    return OBJ_cmp(*ap, &nid_objs[*bp]);
 }
 
 IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, obj);