aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_expr.c
diff options
context:
space:
mode:
authorAndrew Dunstan <andrew@dunslane.net>2022-07-07 17:40:02 -0400
committerAndrew Dunstan <andrew@dunslane.net>2022-07-07 17:45:47 -0400
commit2b2bcc22e571c27a9ea8861e29e0c40874dae714 (patch)
treec782b50bb528f2256b82cf7d230689bad6f3dec1 /src/backend/parser/parse_expr.c
parentea9e59d701b3bfdfebcc67647ed203fa22eed9b0 (diff)
downloadpostgresql-2b2bcc22e571c27a9ea8861e29e0c40874dae714.tar.gz
postgresql-2b2bcc22e571c27a9ea8861e29e0c40874dae714.zip
Only allow returning string types or bytea from json_serialize
These are documented to be the allowed types for the RETURNING clause, but the restriction was not being enforced, which caused a segfault if another type was specified. Add some testing for this. Per report from a.kozhemyakin Backpatch to release 15.
Diffstat (limited to 'src/backend/parser/parse_expr.c')
-rw-r--r--src/backend/parser/parse_expr.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c
index 0dc2fc472e5..efcf1cd5abc 100644
--- a/src/backend/parser/parse_expr.c
+++ b/src/backend/parser/parse_expr.c
@@ -4574,7 +4574,24 @@ transformJsonSerializeExpr(ParseState *pstate, JsonSerializeExpr *expr)
JsonReturning *returning;
if (expr->output)
+ {
returning = transformJsonOutput(pstate, expr->output, true);
+
+ if (returning->typid != BYTEAOID)
+ {
+ char typcategory;
+ bool typispreferred;
+
+ get_type_category_preferred(returning->typid, &typcategory,
+ &typispreferred);
+ if (typcategory != TYPCATEGORY_STRING)
+ ereport(ERROR,
+ (errcode(ERRCODE_DATATYPE_MISMATCH),
+ errmsg("cannot use RETURNING type %s in JSON_SERIALIZE",
+ format_type_be(returning->typid)),
+ errhint("Try returning a string type or bytea")));
+ }
+ }
else
{
/* RETURNING TEXT FORMAT JSON is by default */