Check column list length in XMLTABLE/JSON_TABLE alias
authorAlvaro Herrera
Wed, 18 May 2022 18:28:31 +0000 (20:28 +0200)
committerAlvaro Herrera
Wed, 18 May 2022 18:28:31 +0000 (20:28 +0200)
commit80656f00f85668bb828c1eb878876e5bedcbf4c4
treee36ea5ffaa517fd4f07649bca5383f101ea0c666
parent2e9559b30239ce3cf69383ced208a72a7eb99335
Check column list length in XMLTABLE/JSON_TABLE alias

We weren't checking the length of the column list in the alias clause of
an XMLTABLE or JSON_TABLE function (a "tablefunc" RTE), and it was
possible to make the server crash by passing an overly long one.  Fix it
by throwing an error in that case, like the other places that deal with
alias lists.

In passing, modify the equivalent test used for join RTEs to look like
the other ones, which was different for no apparent reason.

This bug came in when XMLTABLE was born in version 10; backpatch to all
stable versions.

Reported-by: Wang Ke
Discussion: https://postgr.es/m/17480-1c9d73565bb28e90@postgresql.org
src/backend/parser/parse_clause.c
src/backend/parser/parse_relation.c
src/test/regress/expected/int2.out
src/test/regress/expected/join.out
src/test/regress/expected/with.out
src/test/regress/expected/xml.out
src/test/regress/sql/int2.sql
src/test/regress/sql/join.sql
src/test/regress/sql/with.sql
src/test/regress/sql/xml.sql