]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
params: fix conditionals in param parser generation script
authorPauli <ppzgs1@gmail.com>
Wed, 13 Aug 2025 03:56:42 +0000 (13:56 +1000)
committerPauli <ppzgs1@gmail.com>
Fri, 15 Aug 2025 01:03:11 +0000 (11:03 +1000)
These problems only occur in edge cases when using conditional parameters.
I.e. not a problem before now.

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28243)

util/perl/OpenSSL/paramnames.pm

index 003c65fc83199c56e1824df86875c66e0dab3f3f..786b73816324fff21a440e0a83ce0e719911227c 100644 (file)
@@ -637,6 +637,16 @@ sub output_ifdef {
     }
 }
 
+sub output_else {
+    my $cond = shift;
+    my $body = shift;
+
+    if (defined($cond)) {
+        print "# else\n";
+        print($body);
+    }
+}
+
 sub output_endifdef {
     my $cond = shift;
 
@@ -715,6 +725,12 @@ sub generate_decoder_from_trie {
         print ")) {\n";
         trie_matched($field, $num, $indent1, $indent2);
         printf "%s}\n", $indent0;
+
+        # If this is at the top level and it's conditional, we have to
+        # insert an empty statement in an else branch to avoid badness.
+        # This isn't a problem at any other level since those are always
+        # followed by a break statement.
+        output_else($ifdefs->{$field}, $indent0 . ";\n") if ($n == 0);
         output_endifdef($ifdefs->{$field});
         return;
     }
@@ -727,8 +743,8 @@ sub generate_decoder_from_trie {
             $field = $identmap->{$trieref->{'val'}};
             my $num = $concat_num->{$field};
             printf "%sbreak;\n", $indent1;
-            output_ifdef($ifdefs->{$field});
             printf "%scase '\\0':\n", $indent0;
+            output_ifdef($ifdefs->{$field});
             trie_matched($field, $num, $indent1, $indent2);
             output_endifdef($ifdefs->{$field});
         } else {
@@ -837,6 +853,8 @@ sub output_param_decoder {
             } elsif ($pnum eq 'fips') {
                 # The `#if' is added on output
                 $ifdefs{$pident} = ' defined(FIPS_MODULE)';
+            } elsif ($pnum eq '!fips') {
+                $ifdefs{$pident} = ' !defined(FIPS_MODULE)';
             } elsif (substr($pnum, 0, 3) eq '#if') {
                 # Trim the `#if' from the front
                 $ifdefs{$pident} = substr($pnum, 3);
@@ -867,6 +885,11 @@ sub output_param_decoder {
             } else {
                 printf "    OSSL_PARAM *%s;\n", $pident;
             }
+
+            # If this is the only field and it's conditional, we have to
+            # insert a dummy field to avoid an empty struct
+            output_else($ifdefs{$pident}, "    int dummy; /* unused */\n")
+                if (keys(%prms) == 1);
             output_endifdef($ifdefs{$pident});
         }
     }