Skip to content

Commit ef59fa0

Browse files
committed
Ensure the previous Perl interpreter selection is restored upon exit from
plperl_call_handler, in both the normal and error-exit paths. Per report from Alexey Klyukin.
1 parent fb5d058 commit ef59fa0

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/pl/plperl/plperl.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**********************************************************************
22
* plperl.c - perl as a procedural language for PostgreSQL
33
*
4-
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.152 2009/09/28 17:31:12 adunstan Exp $
4+
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.153 2009/10/31 18:11:59 tgl Exp $
55
*
66
**********************************************************************/
77

@@ -150,8 +150,8 @@ void _PG_init(void);
150150
static void plperl_init_interp(void);
151151

152152
static Datum plperl_func_handler(PG_FUNCTION_ARGS);
153-
154153
static Datum plperl_trigger_handler(PG_FUNCTION_ARGS);
154+
155155
static plperl_proc_desc *compile_plperl_function(Oid fn_oid, bool is_trigger);
156156

157157
static SV *plperl_hash_from_tuple(HeapTuple tuple, TupleDesc tupdesc);
@@ -380,11 +380,13 @@ check_interp(bool trusted)
380380
}
381381
}
382382

383-
383+
/*
384+
* Restore previous interpreter selection, if two are active
385+
*/
384386
static void
385387
restore_context(bool old_context)
386388
{
387-
if (trusted_context != old_context)
389+
if (interp_state == INTERP_BOTH && trusted_context != old_context)
388390
{
389391
if (old_context)
390392
PERL_SET_CONTEXT(plperl_trusted_interp);
@@ -870,9 +872,9 @@ Datum
870872
plperl_call_handler(PG_FUNCTION_ARGS)
871873
{
872874
Datum retval;
873-
plperl_call_data *save_call_data;
875+
plperl_call_data *save_call_data = current_call_data;
876+
bool oldcontext = trusted_context;
874877

875-
save_call_data = current_call_data;
876878
PG_TRY();
877879
{
878880
if (CALLED_AS_TRIGGER(fcinfo))
@@ -883,11 +885,13 @@ plperl_call_handler(PG_FUNCTION_ARGS)
883885
PG_CATCH();
884886
{
885887
current_call_data = save_call_data;
888+
restore_context(oldcontext);
886889
PG_RE_THROW();
887890
}
888891
PG_END_TRY();
889892

890893
current_call_data = save_call_data;
894+
restore_context(oldcontext);
891895
return retval;
892896
}
893897

@@ -1226,7 +1230,6 @@ plperl_func_handler(PG_FUNCTION_ARGS)
12261230
Datum retval;
12271231
ReturnSetInfo *rsi;
12281232
SV *array_ret = NULL;
1229-
bool oldcontext = trusted_context;
12301233
ErrorContextCallback pl_error_context;
12311234

12321235
/*
@@ -1376,9 +1379,6 @@ plperl_func_handler(PG_FUNCTION_ARGS)
13761379
if (array_ret == NULL)
13771380
SvREFCNT_dec(perlret);
13781381

1379-
current_call_data = NULL;
1380-
restore_context(oldcontext);
1381-
13821382
return retval;
13831383
}
13841384

@@ -1391,7 +1391,6 @@ plperl_trigger_handler(PG_FUNCTION_ARGS)
13911391
Datum retval;
13921392
SV *svTD;
13931393
HV *hvTD;
1394-
bool oldcontext = trusted_context;
13951394
ErrorContextCallback pl_error_context;
13961395

13971396
/*
@@ -1491,8 +1490,6 @@ plperl_trigger_handler(PG_FUNCTION_ARGS)
14911490
if (perlret)
14921491
SvREFCNT_dec(perlret);
14931492

1494-
current_call_data = NULL;
1495-
restore_context(oldcontext);
14961493
return retval;
14971494
}
14981495

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