Commit ef59fa04 authored by Tom Lane's avatar Tom Lane

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.
parent fb5d0580
/********************************************************************** /**********************************************************************
* plperl.c - perl as a procedural language for PostgreSQL * plperl.c - perl as a procedural language for PostgreSQL
* *
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.152 2009/09/28 17:31:12 adunstan Exp $ * $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.153 2009/10/31 18:11:59 tgl Exp $
* *
**********************************************************************/ **********************************************************************/
...@@ -150,8 +150,8 @@ void _PG_init(void); ...@@ -150,8 +150,8 @@ void _PG_init(void);
static void plperl_init_interp(void); static void plperl_init_interp(void);
static Datum plperl_func_handler(PG_FUNCTION_ARGS); static Datum plperl_func_handler(PG_FUNCTION_ARGS);
static Datum plperl_trigger_handler(PG_FUNCTION_ARGS); static Datum plperl_trigger_handler(PG_FUNCTION_ARGS);
static plperl_proc_desc *compile_plperl_function(Oid fn_oid, bool is_trigger); static plperl_proc_desc *compile_plperl_function(Oid fn_oid, bool is_trigger);
static SV *plperl_hash_from_tuple(HeapTuple tuple, TupleDesc tupdesc); static SV *plperl_hash_from_tuple(HeapTuple tuple, TupleDesc tupdesc);
...@@ -380,11 +380,13 @@ check_interp(bool trusted) ...@@ -380,11 +380,13 @@ check_interp(bool trusted)
} }
} }
/*
* Restore previous interpreter selection, if two are active
*/
static void static void
restore_context(bool old_context) restore_context(bool old_context)
{ {
if (trusted_context != old_context) if (interp_state == INTERP_BOTH && trusted_context != old_context)
{ {
if (old_context) if (old_context)
PERL_SET_CONTEXT(plperl_trusted_interp); PERL_SET_CONTEXT(plperl_trusted_interp);
...@@ -870,9 +872,9 @@ Datum ...@@ -870,9 +872,9 @@ Datum
plperl_call_handler(PG_FUNCTION_ARGS) plperl_call_handler(PG_FUNCTION_ARGS)
{ {
Datum retval; Datum retval;
plperl_call_data *save_call_data; plperl_call_data *save_call_data = current_call_data;
bool oldcontext = trusted_context;
save_call_data = current_call_data;
PG_TRY(); PG_TRY();
{ {
if (CALLED_AS_TRIGGER(fcinfo)) if (CALLED_AS_TRIGGER(fcinfo))
...@@ -883,11 +885,13 @@ plperl_call_handler(PG_FUNCTION_ARGS) ...@@ -883,11 +885,13 @@ plperl_call_handler(PG_FUNCTION_ARGS)
PG_CATCH(); PG_CATCH();
{ {
current_call_data = save_call_data; current_call_data = save_call_data;
restore_context(oldcontext);
PG_RE_THROW(); PG_RE_THROW();
} }
PG_END_TRY(); PG_END_TRY();
current_call_data = save_call_data; current_call_data = save_call_data;
restore_context(oldcontext);
return retval; return retval;
} }
...@@ -1226,7 +1230,6 @@ plperl_func_handler(PG_FUNCTION_ARGS) ...@@ -1226,7 +1230,6 @@ plperl_func_handler(PG_FUNCTION_ARGS)
Datum retval; Datum retval;
ReturnSetInfo *rsi; ReturnSetInfo *rsi;
SV *array_ret = NULL; SV *array_ret = NULL;
bool oldcontext = trusted_context;
ErrorContextCallback pl_error_context; ErrorContextCallback pl_error_context;
/* /*
...@@ -1376,9 +1379,6 @@ plperl_func_handler(PG_FUNCTION_ARGS) ...@@ -1376,9 +1379,6 @@ plperl_func_handler(PG_FUNCTION_ARGS)
if (array_ret == NULL) if (array_ret == NULL)
SvREFCNT_dec(perlret); SvREFCNT_dec(perlret);
current_call_data = NULL;
restore_context(oldcontext);
return retval; return retval;
} }
...@@ -1391,7 +1391,6 @@ plperl_trigger_handler(PG_FUNCTION_ARGS) ...@@ -1391,7 +1391,6 @@ plperl_trigger_handler(PG_FUNCTION_ARGS)
Datum retval; Datum retval;
SV *svTD; SV *svTD;
HV *hvTD; HV *hvTD;
bool oldcontext = trusted_context;
ErrorContextCallback pl_error_context; ErrorContextCallback pl_error_context;
/* /*
...@@ -1491,8 +1490,6 @@ plperl_trigger_handler(PG_FUNCTION_ARGS) ...@@ -1491,8 +1490,6 @@ plperl_trigger_handler(PG_FUNCTION_ARGS)
if (perlret) if (perlret)
SvREFCNT_dec(perlret); SvREFCNT_dec(perlret);
current_call_data = NULL;
restore_context(oldcontext);
return retval; return retval;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment