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

Commite6e50ad

Browse files
committed
Don't crash if cursor_to_xmlschema is used on a non-data-returning Portal.
cursor_to_xmlschema() assumed that any Portal must have a tupDesc,which is not so. Add a defensive check.It's plausible that this mistake occurred because of the ratherpoorly chosen name of the lookup function SPI_cursor_find(),which in such cases is returning something that isn't very muchlike a cursor. Add some documentation to try to forestall futureerrors of the same ilk.Report and patch by Boyu Yang (docs changes by me). Back-patchto all supported branches.Discussion:https://postgr.es/m/dd343010-c637-434c-a8cb-418f53bda3b8.yangboyu.yby@alibaba-inc.com
1 parentc5b7f79 commite6e50ad

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

‎doc/src/sgml/spi.sgml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,6 +2092,19 @@ Portal SPI_cursor_find(const char * <parameter>name</parameter>)
20922092
<symbol>NULL</symbol> if none was found
20932093
</para>
20942094
</refsect1>
2095+
2096+
<refsect1>
2097+
<title>Notes</title>
2098+
2099+
<para>
2100+
Beware that this function can return a <type>Portal</type> object
2101+
that does not have cursor-like properties; for example it might not
2102+
return tuples. If you simply pass the <type>Portal</type> pointer
2103+
to other SPI functions, they can defend themselves against such
2104+
cases, but caution is appropriate when directly inspecting
2105+
the <type>Portal</type>.
2106+
</para>
2107+
</refsect1>
20952108
</refentry>
20962109

20972110
<!-- *********************************************** -->

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2762,6 +2762,10 @@ cursor_to_xmlschema(PG_FUNCTION_ARGS)
27622762
ereport(ERROR,
27632763
(errcode(ERRCODE_UNDEFINED_CURSOR),
27642764
errmsg("cursor \"%s\" does not exist",name)));
2765+
if (portal->tupDesc==NULL)
2766+
ereport(ERROR,
2767+
(errcode(ERRCODE_INVALID_CURSOR_STATE),
2768+
errmsg("portal \"%s\" does not return tuples",name)));
27652769

27662770
xmlschema=_SPI_strdup(map_sql_table_to_xmlschema(portal->tupDesc,
27672771
InvalidOid,nulls,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp