Skip to content

Commit 8ec638e

Browse files
committed
Fix ecpg bugs caused by missing semicolons in the backend grammar.
The Bison documentation clearly states that a semicolon is required after every grammar rule, and our scripts that generate ecpg's grammar from the backend's implicitly assumed this is true. But it turns out that only ancient versions of Bison actually enforce that. There have been a couple of rules without trailing semicolons in gram.y for some time, and as a consequence, ecpg's grammar was faulty and produced wrong output for the affected statements. To fix, add the missing semis, and add some cross-checks to ecpg's scripts so that they'll bleat if we mess this up again. The cases that were broken were: * "SET variable = DEFAULT" (but not "SET variable TO DEFAULT"), as well as allied syntaxes such as ALTER SYSTEM SET ... DEFAULT. These produced syntactically invalid output that the server would reject. * Multiple type names in DROP TYPE/DOMAIN commands. Only the first type name would be listed in the emitted command. Per report from Daisuke Higuchi. Back-patch to all supported versions. Discussion: https://postgr.es/m/1803D792815FC24D871C00D17AE95905DB51CE@g01jpexmbkw24
1 parent bcf6278 commit 8ec638e

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/backend/parser/gram.y

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,7 @@ generic_set:
14431443
n->name = $1;
14441444
$$ = n;
14451445
}
1446+
;
14461447

14471448
set_rest_more: /* Generic SET syntaxes: */
14481449
generic_set {$$ = $1;}
@@ -6192,6 +6193,7 @@ attrs: '.' attr_name
61926193
type_name_list:
61936194
Typename { $$ = list_make1($1); }
61946195
| type_name_list ',' Typename { $$ = lappend($1, $3); }
6196+
;
61956197

61966198
/*****************************************************************************
61976199
*

src/interfaces/ecpg/preproc/check_rules.pl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/perl
22
# src/interfaces/ecpg/preproc/check_rules.pl
3-
# test parser generater for ecpg
4-
# call with backend parser as stdin
3+
# test parser generator for ecpg
4+
# call with backend grammar as stdin
55
#
66
# Copyright (c) 2009-2017, PostgreSQL Global Development Group
77
#
@@ -47,6 +47,7 @@
4747

4848
my $block = '';
4949
my $yaccmode = 0;
50+
my $in_rule = 0;
5051
my $brace_indent = 0;
5152
my (@arr, %found);
5253
my $comment = 0;
@@ -131,10 +132,14 @@
131132
$found{$block} = 1;
132133
$cc++;
133134
$block = '';
135+
$in_rule = 0 if $arr[$fieldIndexer] eq ';';
134136
}
135137
elsif (($arr[$fieldIndexer] =~ '[A-Za-z0-9]+:')
136138
|| $arr[ $fieldIndexer + 1 ] eq ':')
137139
{
140+
die "unterminated rule at grammar line $.\n"
141+
if $in_rule;
142+
$in_rule = 1;
138143
$non_term_id = $arr[$fieldIndexer];
139144
$non_term_id =~ tr/://d;
140145
}
@@ -145,6 +150,9 @@
145150
}
146151
}
147152

153+
die "unterminated rule at end of grammar\n"
154+
if $in_rule;
155+
148156
close $parser_fh;
149157
if ($verbose)
150158
{

src/interfaces/ecpg/preproc/parse.pl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
my $copymode = 0;
2323
my $brace_indent = 0;
2424
my $yaccmode = 0;
25+
my $in_rule = 0;
2526
my $header_included = 0;
2627
my $feature_not_supported = 0;
2728
my $tokenmode = 0;
@@ -288,6 +289,7 @@ sub main
288289
@fields = ();
289290
$infield = 0;
290291
$line = '';
292+
$in_rule = 0;
291293
next;
292294
}
293295

@@ -365,6 +367,9 @@ sub main
365367
$line = '';
366368
@fields = ();
367369
$infield = 1;
370+
die "unterminated rule at grammar line $.\n"
371+
if $in_rule;
372+
$in_rule = 1;
368373
next;
369374
}
370375
elsif ($copymode)
@@ -415,6 +420,9 @@ sub main
415420
}
416421
}
417422
}
423+
die "unterminated rule at end of grammar\n"
424+
if $in_rule;
425+
return;
418426
}
419427

420428

0 commit comments

Comments
 (0)