Skip to content

Commit b4cc35f

Browse files
committed
Tighten coding for non-composite case in plperl's return_next.
Coverity complained about this code's practice of using scalar variables as single-element arrays. While that's really just nitpicking, it probably is more readable to declare them as arrays, so let's do that. A more important point is that the code was just blithely assuming that the result tupledesc has exactly one column; if it doesn't, we'd likely get a crash of some sort in tuplestore_putvalues. Since the tupledesc is manufactured outside of plperl, that seems like an uncomfortably long chain of assumptions. We can nail it down at little cost with a sanity check earlier in the function.
1 parent d2a51e3 commit b4cc35f

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-
Datum ret;
3304-
bool isNull;
3309+
Datum ret[1];
3310+
bool isNull[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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy