Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit486ea0b

Browse files
committed
Fix crash in json_to_record().
json_to_record() depends on get_call_result_type() for the tupledescriptor of the record that should be returned, but in some casesthat cannot be determined. Add a guard to check if the tupledescriptor has been properly resolved, similar to other callers ofget_call_result_type().Also add guard for two other callers of get_call_result_type() injsonfuncs.c. Although json_to_record() is the only actual bug, it's agood idea to follow convention.
1 parentfccebe4 commit486ea0b

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

‎src/backend/utils/adt/jsonfuncs.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,11 @@ each_worker(PG_FUNCTION_ARGS, bool as_text)
941941

942942
rsi->returnMode=SFRM_Materialize;
943943

944-
(void)get_call_result_type(fcinfo,NULL,&tupdesc);
944+
if (get_call_result_type(fcinfo,NULL,&tupdesc)!=TYPEFUNC_COMPOSITE)
945+
ereport(ERROR,
946+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
947+
errmsg("function returning record called in context "
948+
"that cannot accept type record")));
945949

946950
/* make these in a sufficiently long-lived memory context */
947951
old_cxt=MemoryContextSwitchTo(rsi->econtext->ecxt_per_query_memory);
@@ -1349,7 +1353,13 @@ populate_record_worker(PG_FUNCTION_ARGS, bool have_record_arg)
13491353

13501354
json=PG_GETARG_TEXT_P(0);
13511355

1352-
get_call_result_type(fcinfo,NULL,&tupdesc);
1356+
if (get_call_result_type(fcinfo,NULL,&tupdesc)!=TYPEFUNC_COMPOSITE)
1357+
ereport(ERROR,
1358+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1359+
errmsg("function returning record called in context "
1360+
"that cannot accept type record"),
1361+
errhint("Try calling the function in the FROM clause "
1362+
"using a column definition list.")));
13531363
}
13541364

13551365
json_hash=get_json_object_as_hash(json,"json_populate_record",
@@ -1713,7 +1723,11 @@ populate_recordset_worker(PG_FUNCTION_ARGS, bool have_record_arg)
17131723
* get the tupdesc from the result set info - it must be a record type
17141724
* because we already checked that arg1 is a record type.
17151725
*/
1716-
(void)get_call_result_type(fcinfo,NULL,&tupdesc);
1726+
if (get_call_result_type(fcinfo,NULL,&tupdesc)!=TYPEFUNC_COMPOSITE)
1727+
ereport(ERROR,
1728+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1729+
errmsg("function returning record called in context "
1730+
"that cannot accept type record")));
17171731

17181732
state=palloc0(sizeof(PopulateRecordsetState));
17191733
sem=palloc0(sizeof(JsonSemAction));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp