From: Pauli Date: Wed, 13 Aug 2025 03:56:42 +0000 (+1000) Subject: params: fix conditionals in param parser generation script X-Git-Tag: openssl-3.6.0-alpha1~121 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b7c555fecf7670906364d2986674ece7423d90e;p=thirdparty%2Fopenssl.git params: fix conditionals in param parser generation script These problems only occur in edge cases when using conditional parameters. I.e. not a problem before now. Reviewed-by: Shane Lontis Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/28243) --- diff --git a/util/perl/OpenSSL/paramnames.pm b/util/perl/OpenSSL/paramnames.pm index 003c65fc831..786b7381632 100644 --- a/util/perl/OpenSSL/paramnames.pm +++ b/util/perl/OpenSSL/paramnames.pm @@ -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}); } }