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

Commitf73fa5a

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 parentd726897 commitf73fa5a

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
@@ -2727,6 +2727,19 @@ Portal SPI_cursor_find(const char * <parameter>name</parameter>)
27272727
<symbol>NULL</symbol> if none was found
27282728
</para>
27292729
</refsect1>
2730+
2731+
<refsect1>
2732+
<title>Notes</title>
2733+
2734+
<para>
2735+
Beware that this function can return a <type>Portal</type> object
2736+
that does not have cursor-like properties; for example it might not
2737+
return tuples. If you simply pass the <type>Portal</type> pointer
2738+
to other SPI functions, they can defend themselves against such
2739+
cases, but caution is appropriate when directly inspecting
2740+
the <type>Portal</type>.
2741+
</para>
2742+
</refsect1>
27302743
</refentry>
27312744

27322745
<!-- *********************************************** -->

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3012,6 +3012,10 @@ cursor_to_xmlschema(PG_FUNCTION_ARGS)
30123012
ereport(ERROR,
30133013
(errcode(ERRCODE_UNDEFINED_CURSOR),
30143014
errmsg("cursor \"%s\" does not exist",name)));
3015+
if (portal->tupDesc==NULL)
3016+
ereport(ERROR,
3017+
(errcode(ERRCODE_INVALID_CURSOR_STATE),
3018+
errmsg("portal \"%s\" does not return tuples",name)));
30153019

30163020
xmlschema=_SPI_strdup(map_sql_table_to_xmlschema(portal->tupDesc,
30173021
InvalidOid,nulls,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp