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

Commit1233370

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 parentd29812c commit1233370

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
@@ -2083,6 +2083,19 @@ Portal SPI_cursor_find(const char * <parameter>name</parameter>)
20832083
<symbol>NULL</symbol> if none was found
20842084
</para>
20852085
</refsect1>
2086+
2087+
<refsect1>
2088+
<title>Notes</title>
2089+
2090+
<para>
2091+
Beware that this function can return a <type>Portal</type> object
2092+
that does not have cursor-like properties; for example it might not
2093+
return tuples. If you simply pass the <type>Portal</type> pointer
2094+
to other SPI functions, they can defend themselves against such
2095+
cases, but caution is appropriate when directly inspecting
2096+
the <type>Portal</type>.
2097+
</para>
2098+
</refsect1>
20862099
</refentry>
20872100

20882101
<!-- *********************************************** -->

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2776,6 +2776,10 @@ cursor_to_xmlschema(PG_FUNCTION_ARGS)
27762776
ereport(ERROR,
27772777
(errcode(ERRCODE_UNDEFINED_CURSOR),
27782778
errmsg("cursor \"%s\" does not exist",name)));
2779+
if (portal->tupDesc==NULL)
2780+
ereport(ERROR,
2781+
(errcode(ERRCODE_INVALID_CURSOR_STATE),
2782+
errmsg("portal \"%s\" does not return tuples",name)));
27792783

27802784
xmlschema=_SPI_strdup(map_sql_table_to_xmlschema(portal->tupDesc,
27812785
InvalidOid,nulls,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp