]> granicus.if.org Git - postgresql/commitdiff
Ensure that PLPGSQL_DTYPE_ROW variables have valid refname fields.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 5 Oct 2018 16:45:37 +0000 (12:45 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 5 Oct 2018 16:45:37 +0000 (12:45 -0400)
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 f9263006d, so back-patch to v11.

Discussion: https://postgr.es/m/CAFj8pRA+3f5n4642q2g8BXCKjbTd7yU9JMYAgDyHgozk6cQ-VA@mail.gmail.com

src/pl/plpgsql/src/pl_comp.c
src/pl/plpgsql/src/pl_exec.c
src/pl/plpgsql/src/pl_gram.y
src/pl/plpgsql/src/plpgsql.h

index 721234d6d292a5da56db5d7f0f058a2695117152..59460d264345da2ac8ca5890bb1f47a2605136d5 100644 (file)
@@ -1896,6 +1896,8 @@ build_row_from_vars(PLpgSQL_variable **vars, int numvars)
 
        row = palloc0(sizeof(PLpgSQL_row));
        row->dtype = PLPGSQL_DTYPE_ROW;
+       row->refname = "(unnamed row)";
+       row->lineno = -1;
        row->rowtupdesc = CreateTemplateTupleDesc(numvars, false);
        row->nfields = numvars;
        row->fieldnames = palloc(numvars * sizeof(char *));
index 574234da50acf06d7637bf5550043c7582323b7c..45526383f25b5493c88ac9b762c65052a22d5897 100644 (file)
@@ -2205,6 +2205,7 @@ exec_stmt_call(PLpgSQL_execstate *estate, PLpgSQL_stmt_call *stmt)
 
                        row = palloc0(sizeof(*row));
                        row->dtype = PLPGSQL_DTYPE_ROW;
+                       row->refname = "(unnamed row)";
                        row->lineno = -1;
                        row->varnos = palloc(sizeof(int) * FUNC_MAX_ARGS);
 
index b59869a534a99a69e8130190061121d8656a1249..68e399f9cff49717e2529bb7690882c4dd724934 100644 (file)
@@ -613,6 +613,7 @@ decl_cursor_args :
 
                                                new = palloc0(sizeof(PLpgSQL_row));
                                                new->dtype = PLPGSQL_DTYPE_ROW;
+                                               new->refname = "(unnamed row)";
                                                new->lineno = plpgsql_location_to_lineno(@1);
                                                new->rowtupdesc = NULL;
                                                new->nfields = list_length($2);
@@ -3526,6 +3527,7 @@ read_into_scalar_list(char *initial_name,
 
        row = palloc0(sizeof(PLpgSQL_row));
        row->dtype = PLPGSQL_DTYPE_ROW;
+       row->refname = "(unnamed row)";
        row->lineno = plpgsql_location_to_lineno(initial_location);
        row->rowtupdesc = NULL;
        row->nfields = nfields;
@@ -3560,6 +3562,7 @@ make_scalar_list1(char *initial_name,
 
        row = palloc0(sizeof(PLpgSQL_row));
        row->dtype = PLPGSQL_DTYPE_ROW;
+       row->refname = "(unnamed row)";
        row->lineno = lineno;
        row->rowtupdesc = NULL;
        row->nfields = 1;
index 4a4c7cbd36e24b43d0bf6bfb803622b4374a4c51..f6c35a5049088c1219bf74dd30dda6e9fa75e6d4 100644 (file)
@@ -326,7 +326,12 @@ typedef struct PLpgSQL_var
  * Note that there's no way to name the row as such from PL/pgSQL code,
  * so many functions don't need to support these.
  *
- * refname, isconst, notnull, and default_val are unsupported (and hence
+ * That also means that there's no real name for the row variable, so we
+ * conventionally set refname to "(unnamed row)".  We could leave it NULL,
+ * but it's too convenient to be able to assume that refname is valid in
+ * all variants of PLpgSQL_variable.
+ *
+ * isconst, notnull, and default_val are unsupported (and hence
  * always zero/null) for a row.  The member variables of a row should have
  * been checked to be writable at compile time, so isconst is correctly set
  * to false.  notnull and default_val aren't applicable.