Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 113a659

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 b5f03dc commit 113a659

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

src/pl/plpgsql/src/pl_comp.c

+2
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

+1
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

+3
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

+6-1
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)