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

Commitb603848

Browse files
committed
Fix memory clobber problem reported by John Hansen: plperl_safe_init()
may expand the Perl stack, therefore we must SPAGAIN to reload the localstack pointer after calling it. Also a couple other marginal readabilityimprovements.
1 parentda1c19a commitb603848

File tree

1 file changed

+38
-47
lines changed

1 file changed

+38
-47
lines changed

‎src/pl/plperl/plperl.c

Lines changed: 38 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* ENHANCEMENTS, OR MODIFICATIONS.
3434
*
3535
* IDENTIFICATION
36-
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.57 2004/11/17 21:23:36 tgl Exp $
36+
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.58 2004/11/18 21:35:42 tgl Exp $
3737
*
3838
**********************************************************************/
3939

@@ -240,7 +240,6 @@ plperl_init_interp(void)
240240
* Initialize the proc and query hash tables
241241
************************************************************/
242242
plperl_proc_hash=newHV();
243-
244243
}
245244

246245

@@ -497,10 +496,7 @@ plperl_get_elem(HV *hash, char *key)
497496
{
498497
SV**svp=hv_fetch(hash,key,strlen(key), FALSE);
499498
if (!svp)
500-
{
501499
elog(ERROR,"plperl: key '%s' not found",key);
502-
returnNULL;
503-
}
504500
returnSvTYPE(*svp)==SVt_NULL ?NULL :SvPV(*svp,PL_na);
505501
}
506502

@@ -659,7 +655,10 @@ plperl_create_sub(char *s, bool trusted)
659655
intcount;
660656

661657
if (trusted&& !plperl_safe_init_done)
658+
{
662659
plperl_safe_init();
660+
SPAGAIN;
661+
}
663662

664663
ENTER;
665664
SAVETMPS;
@@ -760,50 +759,40 @@ plperl_call_perl_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo)
760759
XPUSHs(sv_2mortal(newSVpv("undef",0)));
761760
for (i=0;i<desc->nargs;i++)
762761
{
763-
if (desc->arg_is_rowtype[i])
762+
if (fcinfo->argnull[i])
763+
XPUSHs(&PL_sv_undef);
764+
elseif (desc->arg_is_rowtype[i])
764765
{
765-
if (fcinfo->argnull[i])
766-
XPUSHs(&PL_sv_undef);
767-
else
768-
{
769-
HeapTupleHeadertd;
770-
OidtupType;
771-
int32tupTypmod;
772-
TupleDesctupdesc;
773-
HeapTupleDatatmptup;
774-
SV*hashref;
775-
776-
td=DatumGetHeapTupleHeader(fcinfo->arg[i]);
777-
/* Extract rowtype info and find a tupdesc */
778-
tupType=HeapTupleHeaderGetTypeId(td);
779-
tupTypmod=HeapTupleHeaderGetTypMod(td);
780-
tupdesc=lookup_rowtype_tupdesc(tupType,tupTypmod);
781-
/* Build a temporary HeapTuple control structure */
782-
tmptup.t_len=HeapTupleHeaderGetDatumLength(td);
783-
tmptup.t_data=td;
784-
785-
/*
786-
* plperl_build_tuple_argument better return a mortal SV.
787-
*/
788-
hashref=plperl_build_tuple_argument(&tmptup,tupdesc);
789-
XPUSHs(hashref);
790-
}
766+
HeapTupleHeadertd;
767+
OidtupType;
768+
int32tupTypmod;
769+
TupleDesctupdesc;
770+
HeapTupleDatatmptup;
771+
SV*hashref;
772+
773+
td=DatumGetHeapTupleHeader(fcinfo->arg[i]);
774+
/* Extract rowtype info and find a tupdesc */
775+
tupType=HeapTupleHeaderGetTypeId(td);
776+
tupTypmod=HeapTupleHeaderGetTypMod(td);
777+
tupdesc=lookup_rowtype_tupdesc(tupType,tupTypmod);
778+
/* Build a temporary HeapTuple control structure */
779+
tmptup.t_len=HeapTupleHeaderGetDatumLength(td);
780+
tmptup.t_data=td;
781+
782+
/* plperl_build_tuple_argument better return a mortal SV */
783+
hashref=plperl_build_tuple_argument(&tmptup,tupdesc);
784+
XPUSHs(hashref);
791785
}
792786
else
793787
{
794-
if (fcinfo->argnull[i])
795-
XPUSHs(&PL_sv_undef);
796-
else
797-
{
798-
char*tmp;
799-
800-
tmp=DatumGetCString(FunctionCall3(&(desc->arg_out_func[i]),
801-
fcinfo->arg[i],
802-
ObjectIdGetDatum(desc->arg_typioparam[i]),
803-
Int32GetDatum(-1)));
804-
XPUSHs(sv_2mortal(newSVpv(tmp,0)));
805-
pfree(tmp);
806-
}
788+
char*tmp;
789+
790+
tmp=DatumGetCString(FunctionCall3(&(desc->arg_out_func[i]),
791+
fcinfo->arg[i],
792+
ObjectIdGetDatum(desc->arg_typioparam[i]),
793+
Int32GetDatum(-1)));
794+
XPUSHs(sv_2mortal(newSVpv(tmp,0)));
795+
pfree(tmp);
807796
}
808797
}
809798
PUTBACK;
@@ -848,6 +837,7 @@ plperl_call_perl_trigger_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo, S
848837
{
849838
dSP;
850839
SV*retval;
840+
Trigger*tg_trigger;
851841
inti;
852842
intcount;
853843

@@ -856,8 +846,9 @@ plperl_call_perl_trigger_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo, S
856846

857847
PUSHMARK(sp);
858848
XPUSHs(td);
859-
for (i=0;i< ((TriggerData*)fcinfo->context)->tg_trigger->tgnargs;i++)
860-
XPUSHs(sv_2mortal(newSVpv(((TriggerData*)fcinfo->context)->tg_trigger->tgargs[i],0)));
849+
tg_trigger= ((TriggerData*)fcinfo->context)->tg_trigger;
850+
for (i=0;i<tg_trigger->tgnargs;i++)
851+
XPUSHs(sv_2mortal(newSVpv(tg_trigger->tgargs[i],0)));
861852
PUTBACK;
862853

863854
count=perl_call_sv(desc->reference,G_SCALAR |G_EVAL |G_KEEPERR);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp