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

Commitb4cc35f

Browse files
committed
Tighten coding for non-composite case in plperl's return_next.
Coverity complained about this code's practice of using scalar variablesas single-element arrays. While that's really just nitpicking, it probablyis more readable to declare them as arrays, so let's do that. A moreimportant point is that the code was just blithely assuming that theresult tupledesc has exactly one column; if it doesn't, we'd likely geta crash of some sort in tuplestore_putvalues. Since the tupledesc ismanufactured outside of plperl, that seems like an uncomfortably longchain of assumptions. We can nail it down at little cost with a sanitycheck earlier in the function.
1 parentd2a51e3 commitb4cc35f

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

‎src/pl/plperl/plperl.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3247,12 +3247,18 @@ plperl_return_next_internal(SV *sv)
32473247

32483248
/*
32493249
* This is the first call to return_next in the current PL/Perl
3250-
* function call, so memoize some lookups
3250+
* function call, so identify the output tuple descriptor and create a
3251+
* tuplestore to hold the result rows.
32513252
*/
32523253
if (prodesc->fn_retistuple)
32533254
(void)get_call_result_type(fcinfo,NULL,&tupdesc);
32543255
else
3256+
{
32553257
tupdesc=rsi->expectedDesc;
3258+
/* Protect assumption below that we return exactly one column */
3259+
if (tupdesc==NULL||tupdesc->natts!=1)
3260+
elog(ERROR,"expected single-column result descriptor for non-composite SETOF result");
3261+
}
32563262

32573263
/*
32583264
* Make sure the tuple_store and ret_tdesc are sufficiently
@@ -3300,20 +3306,20 @@ plperl_return_next_internal(SV *sv)
33003306
}
33013307
else
33023308
{
3303-
Datumret;
3304-
boolisNull;
3309+
Datumret[1];
3310+
boolisNull[1];
33053311

3306-
ret=plperl_sv_to_datum(sv,
3307-
prodesc->result_oid,
3308-
-1,
3309-
fcinfo,
3310-
&prodesc->result_in_func,
3311-
prodesc->result_typioparam,
3312-
&isNull);
3312+
ret[0]=plperl_sv_to_datum(sv,
3313+
prodesc->result_oid,
3314+
-1,
3315+
fcinfo,
3316+
&prodesc->result_in_func,
3317+
prodesc->result_typioparam,
3318+
&isNull[0]);
33133319

33143320
tuplestore_putvalues(current_call_data->tuple_store,
33153321
current_call_data->ret_tdesc,
3316-
&ret,&isNull);
3322+
ret,isNull);
33173323
}
33183324

33193325
MemoryContextSwitchTo(old_cxt);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp