Skip to content

Commit 53c2bb7

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 ede6b19 commit 53c2bb7

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/backend/parser/gram.y

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,7 @@ generic_set:
13771377
n->name = $1;
13781378
$$ = n;
13791379
}
1380+
;
13801381

13811382
set_rest_more: /* Generic SET syntaxes: */
13821383
generic_set {$$ = $1;}

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-2014, 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 GRAM;
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;
@@ -285,6 +286,7 @@ sub main
285286
@fields = ();
286287
$infield = 0;
287288
$line = '';
289+
$in_rule = 0;
288290
next;
289291
}
290292

@@ -362,6 +364,9 @@ sub main
362364
$line = '';
363365
@fields = ();
364366
$infield = 1;
367+
die "unterminated rule at grammar line $.\n"
368+
if $in_rule;
369+
$in_rule = 1;
365370
next;
366371
}
367372
elsif ($copymode)
@@ -412,6 +417,9 @@ sub main
412417
}
413418
}
414419
}
420+
die "unterminated rule at end of grammar\n"
421+
if $in_rule;
422+
return;
415423
}
416424

417425

0 commit comments

Comments
 (0)