Skip to content

Commit 6e526b7

Browse files
committed
Ensure that PLPGSQL_DTYPE_ROW variables have valid refname fields.
Without this, the syntax-tree-dumping functions in pl_funcs.c crash, and there are other places that might be at risk too. Per report from Pavel Stehule. Looks like I broke this in commit f926300, so back-patch to v11. Discussion: https://postgr.es/m/CAFj8pRA+3f5n4642q2g8BXCKjbTd7yU9JMYAgDyHgozk6cQ-VA@mail.gmail.com
1 parent 40159d9 commit 6e526b7

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

src/pl/plpgsql/src/pl_comp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,6 +1896,8 @@ build_row_from_vars(PLpgSQL_variable **vars, int numvars)
18961896

18971897
row = palloc0(sizeof(PLpgSQL_row));
18981898
row->dtype = PLPGSQL_DTYPE_ROW;
1899+
row->refname = "(unnamed row)";
1900+
row->lineno = -1;
18991901
row->rowtupdesc = CreateTemplateTupleDesc(numvars, false);
19001902
row->nfields = numvars;
19011903
row->fieldnames = palloc(numvars * sizeof(char *));

src/pl/plpgsql/src/pl_exec.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,6 +2205,7 @@ exec_stmt_call(PLpgSQL_execstate *estate, PLpgSQL_stmt_call *stmt)
22052205

22062206
row = palloc0(sizeof(*row));
22072207
row->dtype = PLPGSQL_DTYPE_ROW;
2208+
row->refname = "(unnamed row)";
22082209
row->lineno = -1;
22092210
row->varnos = palloc(sizeof(int) * FUNC_MAX_ARGS);
22102211

src/pl/plpgsql/src/pl_gram.y

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ decl_cursor_args :
613613

614614
new = palloc0(sizeof(PLpgSQL_row));
615615
new->dtype = PLPGSQL_DTYPE_ROW;
616+
new->refname = "(unnamed row)";
616617
new->lineno = plpgsql_location_to_lineno(@1);
617618
new->rowtupdesc = NULL;
618619
new->nfields = list_length($2);
@@ -3526,6 +3527,7 @@ read_into_scalar_list(char *initial_name,
35263527

35273528
row = palloc0(sizeof(PLpgSQL_row));
35283529
row->dtype = PLPGSQL_DTYPE_ROW;
3530+
row->refname = "(unnamed row)";
35293531
row->lineno = plpgsql_location_to_lineno(initial_location);
35303532
row->rowtupdesc = NULL;
35313533
row->nfields = nfields;
@@ -3560,6 +3562,7 @@ make_scalar_list1(char *initial_name,
35603562

35613563
row = palloc0(sizeof(PLpgSQL_row));
35623564
row->dtype = PLPGSQL_DTYPE_ROW;
3565+
row->refname = "(unnamed row)";
35633566
row->lineno = lineno;
35643567
row->rowtupdesc = NULL;
35653568
row->nfields = 1;

src/pl/plpgsql/src/plpgsql.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,12 @@ typedef struct PLpgSQL_var
326326
* Note that there's no way to name the row as such from PL/pgSQL code,
327327
* so many functions don't need to support these.
328328
*
329-
* refname, isconst, notnull, and default_val are unsupported (and hence
329+
* That also means that there's no real name for the row variable, so we
330+
* conventionally set refname to "(unnamed row)". We could leave it NULL,
331+
* but it's too convenient to be able to assume that refname is valid in
332+
* all variants of PLpgSQL_variable.
333+
*
334+
* isconst, notnull, and default_val are unsupported (and hence
330335
* always zero/null) for a row. The member variables of a row should have
331336
* been checked to be writable at compile time, so isconst is correctly set
332337
* to false. notnull and default_val aren't applicable.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy