Skip to content

Commit 9e138a4

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 f16735d commit 9e138a4

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/backend/parser/gram.y

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,7 @@ generic_set:
14651465
n->name = $1;
14661466
$$ = n;
14671467
}
1468+
;
14681469

14691470
set_rest_more: /* Generic SET syntaxes: */
14701471
generic_set {$$ = $1;}
@@ -6282,6 +6283,7 @@ attrs: '.' attr_name
62826283
type_name_list:
62836284
Typename { $$ = list_make1($1); }
62846285
| type_name_list ',' Typename { $$ = lappend($1, $3); }
6286+
;
62856287

62866288
/*****************************************************************************
62876289
*

src/interfaces/ecpg/preproc/check_rules.pl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/perl
22
# src/interfaces/ecpg/preproc/check_rules.pl
33
# test parser generator for ecpg
4-
# call with backend parser as stdin
4+
# call with backend grammar as stdin
55
#
66
# Copyright (c) 2009-2019, 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: 7 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,8 @@ sub main
415420
}
416421
}
417422
}
423+
die "unterminated rule at end of grammar\n"
424+
if $in_rule;
418425
return;
419426
}
420427

0 commit comments

Comments
 (0)