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

Commitbe3aa30

Browse files
committed
Fix inadequate error checking: you can't assume that fcinfo->resultinfo
is a ReturnSetInfo unless you've tested it with IsA.
1 parent40d091b commitbe3aa30

File tree

2 files changed

+45
-41
lines changed

2 files changed

+45
-41
lines changed

‎contrib/tablefunc/tablefunc.c

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -687,9 +687,13 @@ crosstab_hash(PG_FUNCTION_ARGS)
687687
intnum_categories;
688688

689689
/* check to see if caller supports us returning a tuplestore */
690-
if (!rsinfo|| !(rsinfo->allowedModes&SFRM_Materialize))
690+
if (rsinfo==NULL|| !IsA(rsinfo,ReturnSetInfo))
691691
ereport(ERROR,
692-
(errcode(ERRCODE_SYNTAX_ERROR),
692+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
693+
errmsg("set-valued function called in context that cannot accept a set")));
694+
if (!(rsinfo->allowedModes&SFRM_Materialize))
695+
ereport(ERROR,
696+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
693697
errmsg("materialize mode required, but it is not " \
694698
"allowed in this context")));
695699

@@ -1049,9 +1053,13 @@ connectby_text(PG_FUNCTION_ARGS)
10491053
MemoryContextoldcontext;
10501054

10511055
/* check to see if caller supports us returning a tuplestore */
1052-
if (!rsinfo|| !(rsinfo->allowedModes&SFRM_Materialize))
1056+
if (rsinfo==NULL|| !IsA(rsinfo,ReturnSetInfo))
10531057
ereport(ERROR,
1054-
(errcode(ERRCODE_SYNTAX_ERROR),
1058+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1059+
errmsg("set-valued function called in context that cannot accept a set")));
1060+
if (!(rsinfo->allowedModes&SFRM_Materialize))
1061+
ereport(ERROR,
1062+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
10551063
errmsg("materialize mode required, but it is not " \
10561064
"allowed in this context")));
10571065

@@ -1076,13 +1084,6 @@ connectby_text(PG_FUNCTION_ARGS)
10761084
/* OK, use it then */
10771085
attinmeta=TupleDescGetAttInMetadata(tupdesc);
10781086

1079-
/* check to see if caller supports us returning a tuplestore */
1080-
if (!rsinfo|| !(rsinfo->allowedModes&SFRM_Materialize))
1081-
ereport(ERROR,
1082-
(errcode(ERRCODE_SYNTAX_ERROR),
1083-
errmsg("materialize mode required, but it is not " \
1084-
"allowed in this context")));
1085-
10861087
/* OK, go to work */
10871088
rsinfo->returnMode=SFRM_Materialize;
10881089
rsinfo->setResult=connectby(relname,
@@ -1131,9 +1132,15 @@ connectby_text_serial(PG_FUNCTION_ARGS)
11311132
MemoryContextoldcontext;
11321133

11331134
/* check to see if caller supports us returning a tuplestore */
1134-
if (!rsinfo|| !(rsinfo->allowedModes&SFRM_Materialize))
1135-
elog(ERROR,"connectby: materialize mode required, but it is not "
1136-
"allowed in this context");
1135+
if (rsinfo==NULL|| !IsA(rsinfo,ReturnSetInfo))
1136+
ereport(ERROR,
1137+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1138+
errmsg("set-valued function called in context that cannot accept a set")));
1139+
if (!(rsinfo->allowedModes&SFRM_Materialize))
1140+
ereport(ERROR,
1141+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1142+
errmsg("materialize mode required, but it is not " \
1143+
"allowed in this context")));
11371144

11381145
if (fcinfo->nargs==7)
11391146
{
@@ -1156,11 +1163,6 @@ connectby_text_serial(PG_FUNCTION_ARGS)
11561163
/* OK, use it then */
11571164
attinmeta=TupleDescGetAttInMetadata(tupdesc);
11581165

1159-
/* check to see if caller supports us returning a tuplestore */
1160-
if (!rsinfo->allowedModes&SFRM_Materialize)
1161-
elog(ERROR,"connectby requires Materialize mode, but it is not "
1162-
"allowed in this context");
1163-
11641166
/* OK, go to work */
11651167
rsinfo->returnMode=SFRM_Materialize;
11661168
rsinfo->setResult=connectby(relname,

‎contrib/xml2/xpath.c

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -669,23 +669,36 @@ xpath_table(PG_FUNCTION_ARGS)
669669

670670
StringInfoquerysql;
671671

672-
/* We only have a valid tuple description in table function mode */
672+
/* We only have a valid tuple description in table function mode */
673+
if (rsinfo==NULL|| !IsA(rsinfo,ReturnSetInfo))
674+
ereport(ERROR,
675+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
676+
errmsg("set-valued function called in context that cannot accept a set")));
673677
if (rsinfo->expectedDesc==NULL)
674-
{
675-
ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR),
676-
errmsg("xpath_table must be called as a table function")));
677-
}
678+
ereport(ERROR,
679+
(errcode(ERRCODE_SYNTAX_ERROR),
680+
errmsg("xpath_table must be called as a table function")));
678681

679-
/* The tuplestore must exist in a higher context than
680-
* this function call (per_query_ctx is used) */
682+
/*
683+
* We want to materialise because it means that we don't have to carry
684+
* libxml2 parser state between invocations of this function
685+
*/
686+
if (!(rsinfo->allowedModes&SFRM_Materialize))
687+
ereport(ERROR,
688+
(errcode(ERRCODE_SYNTAX_ERROR),
689+
errmsg("xpath_table requires Materialize mode, but it is not "
690+
"allowed in this context")));
691+
692+
/* The tuplestore must exist in a higher context than
693+
* this function call (per_query_ctx is used)
694+
*/
681695

682696
per_query_ctx=rsinfo->econtext->ecxt_per_query_memory;
683697
oldcontext=MemoryContextSwitchTo(per_query_ctx);
684698

685-
/* Create the tuplestore - work_mem is the max in-memory size before a
686-
* file is created on disk to hold it.
687-
*/
688-
699+
/* Create the tuplestore - work_mem is the max in-memory size before a
700+
* file is created on disk to hold it.
701+
*/
689702
tupstore=tuplestore_begin_heap(true, false,work_mem);
690703

691704
MemoryContextSwitchTo(oldcontext);
@@ -703,17 +716,6 @@ xpath_table(PG_FUNCTION_ARGS)
703716

704717
attinmeta=TupleDescGetAttInMetadata(ret_tupdesc);
705718

706-
/*
707-
* We want to materialise because it means that we don't have to carry
708-
* libxml2 parser state between invocations of this function
709-
*/
710-
711-
/* check to see if caller supports us returning a tuplestore */
712-
if (!rsinfo|| !(rsinfo->allowedModes&SFRM_Materialize))
713-
ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR),
714-
errmsg("xpath_table requires Materialize mode, but it is not "
715-
"allowed in this context")));
716-
717719
/* Set return mode and allocate value space. */
718720
rsinfo->returnMode=SFRM_Materialize;
719721
rsinfo->setDesc=ret_tupdesc;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp