mirror of
https://github.com/postgres/postgres.git
synced 2025-06-27 23:21:58 +03:00
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.
This commit is contained in:
@ -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 */
|
||||
|
Reference in New Issue
Block a user