From 33634107d72866cb85544f274a217ad592f61fe0 Mon Sep 17 00:00:00 2001 From: Zsolt Parragi Date: Sun, 15 Mar 2026 11:22:00 +0000 Subject: [PATCH 2/4] gen_guc_tables: reject type-inappropriate fields in guc_parameters.dat Detect when a GUC entry has fields that don't apply to its type, such as "min" or "max" on a bool or string, or "options" on an int. These would be silently ignored, likely indicating a copy-paste mistake. The existing required_by_type structure is replaced with a single type_specific_fields hash that drives both the required-field and inappropriate-field checks. --- src/backend/utils/misc/gen_guc_tables.pl | 32 ++++++++++++++++++------ 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/backend/utils/misc/gen_guc_tables.pl b/src/backend/utils/misc/gen_guc_tables.pl index ba2e6f001f1..b1c1b7afc6c 100644 --- a/src/backend/utils/misc/gen_guc_tables.pl +++ b/src/backend/utils/misc/gen_guc_tables.pl @@ -45,12 +45,12 @@ sub validate_guc_entry my @required_common = qw(name type context group short_desc variable boot_val); - my %required_by_type = ( - int => [qw(min max)], - real => [qw(min max)], - enum => [qw(options)], - bool => [], # no extra required fields - string => [], # no extra required fields + my %type_specific_fields = ( + int => { map { $_ => 1 } qw(min max) }, + real => { map { $_ => 1 } qw(min max) }, + enum => { map { $_ => 1 } qw(options) }, + bool => {}, + string => {}, ); # All fields recognized by the generator. "line_number" is injected @@ -83,7 +83,7 @@ sub validate_guc_entry } } - unless (exists $required_by_type{ $entry->{type} }) + unless (exists $type_specific_fields{ $entry->{type} }) { die sprintf( qq{%s:%d: error: entry "%s" has unrecognized GUC type "%s"\n}, @@ -91,7 +91,9 @@ sub validate_guc_entry $entry->{name}, $entry->{type} // ''); } - for my $f (@{ $required_by_type{ $entry->{type} } }) + my $fields_for_type = $type_specific_fields{ $entry->{type} }; + + for my $f (sort keys %$fields_for_type) { unless (defined $entry->{$f}) { @@ -101,6 +103,20 @@ sub validate_guc_entry $entry->{type}, $f); } } + + my %all_type_specific; + $all_type_specific{$_} = 1 + for map { keys %$_ } values %type_specific_fields; + for my $f (sort keys %$entry) + { + if ($all_type_specific{$f} && !$fields_for_type->{$f}) + { + die sprintf( + qq{%s:%d: error: entry "%s" of type "%s" must not have field "%s"\n}, + $input_fname, $entry->{line_number}, $entry->{name}, + $entry->{type}, $f); + } + } } # Print GUC table. -- 2.43.0