mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-31 12:37:24 +02:00
Fix handling of pgbench's hash when no argument is provided
Depending on the platform used, this can cause a crash in the worst case, or an unhelpful error message, so fail gracefully. Author: Fabien Coelho Discussion: https://postgr.es/m/alpine.DEB.2.21.1807262302550.29874@lancre Backpatch: 11-, where hash() has been added in pgbench.
This commit is contained in:
parent
c606f10ff8
commit
c2e5f60db1
@ -467,7 +467,7 @@ make_func(yyscan_t yyscanner, int fnumber, PgBenchExprList *args)
|
||||
|
||||
/* hash functions with optional seed argument */
|
||||
case PGBENCH_NARGS_HASH:
|
||||
if (len > 2)
|
||||
if (len < 1 || len > 2)
|
||||
expr_yyerror_more(yyscanner, "unexpected number of arguments",
|
||||
PGBENCH_FUNCTIONS[fnumber].fname);
|
||||
|
||||
|
@ -266,6 +266,26 @@ my @script_tests = (
|
||||
'endif syntax error',
|
||||
[qr{unexpected argument in command "endif"}],
|
||||
{ 'endif-bad.sql' => "\\if 0\n\\endif BAD\n" }
|
||||
],
|
||||
[
|
||||
'not enough arguments for least',
|
||||
[qr{at least one argument expected \(least\)}],
|
||||
{ 'bad-least.sql' => "\\set i least()\n" }
|
||||
],
|
||||
[
|
||||
'not enough arguments for greatest',
|
||||
[qr{at least one argument expected \(greatest\)}],
|
||||
{ 'bad-greatest.sql' => "\\set i greatest()\n" }
|
||||
],
|
||||
[
|
||||
'not enough arguments for hash',
|
||||
[qr{unexpected number of arguments \(hash\)}],
|
||||
{ 'bad-hash-1.sql' => "\\set i hash()\n" }
|
||||
],
|
||||
[
|
||||
'too many arguments for hash',
|
||||
[qr{unexpected number of arguments \(hash\)}],
|
||||
{ 'bad-hash-2.sql' => "\\set i hash(1,2,3)\n" }
|
||||
],);
|
||||
|
||||
for my $t (@script_tests)
|
||||
|
Loading…
Reference in New Issue
Block a user