]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Don't rely on cmp of uninitialized values in obj_dat.pl
authorBob Beck <beck@openssl.org>
Thu, 30 Apr 2026 16:34:28 +0000 (10:34 -0600)
committerNeil Horman <nhorman@openssl.org>
Thu, 7 May 2026 15:41:04 +0000 (11:41 -0400)
Since we use this for a sort, in theory this could become
inconsistent if we were to do a make update, re-generate
the output, and check it in from a different development
platform that returns different inconsistencies in how
cmp behaves on uninitialized values.

Rather than ponder this, just make this consistent
by ensuring undefined values have 0 length, and remove
the disabling of the warnings in obj_cmp

Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Norbert Pocs <norbertp@openssl.org>
Reviewed-by: Nikola Pajkovsky <nikolap@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
MergeDate: Thu May  7 15:41:12 2026
(Merged from https://github.com/openssl/openssl/pull/31046)

crypto/objects/obj_dat.pl

index 12836e1bbd19dec24680fbb205951a5b3c9912b6..a2bba8b0fa707bfcb3f5f215aadc29772f26504a 100644 (file)
@@ -219,11 +219,11 @@ printf "static const unsigned int obj_objs[NUM_OBJ] = {\n";
 # Compare DER; prefer shorter; if some length, use the "smaller" encoding.
 sub obj_cmp
 {
-    no warnings "uninitialized";
-    my $A = $obj_len{$obj{$nid{$a}}};
-    my $B = $obj_len{$obj{$nid{$b}}};
+    my $A = defined($obj_len{$obj{$nid{$a}}}) ? $obj_len{$obj{$nid{$a}}} : 0;
+    my $B = defined($obj_len{$obj{$nid{$b}}}) ? $obj_len{$obj{$nid{$b}}} : 0;
     my $r = $A - $B;
     return $r if $r != 0;
+    return 0 if $A == 0;
 
     $A = $obj_der{$obj{$nid{$a}}};
     $B = $obj_der{$obj{$nid{$b}}};