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

Commitfe922de

Browse files
committed
Security fix for plperl.
1 parent8573615 commitfe922de

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

‎src/pl/plperl/Makefile.PL

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ my $opcode = '';
5151
}
5252

5353
my$perllib ="-L$Config{archlibexp}/CORE -lperl";
54-
my$dynalib ="$Config{archlibexp}/auto/DynaLoader/DynaLoader.a";
5554

5655
WriteMakefile('NAME'=>'plperl',
57-
dynamic_lib=> {'OTHERLDFLAGS'=>"$opcode$perllib$dynalib" } ,
56+
dynamic_lib=> {'OTHERLDFLAGS'=>"$opcode$perllib" } ,
5857
INC=>'-I$(SRCDIR)/include -I$(SRCDIR)/backend',
5958
XS=> {'SPI.xs'=>'SPI.c' },
6059
OBJECT=>'plperl.o eloglvl.o SPI.o',

‎src/pl/plperl/plperl.c

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,15 @@ static void
219219
plperl_init_safe_interp(void)
220220
{
221221

222-
char*embedding[]= {"","-e","use DynaLoader; require Safe; SPI::bootstrap()","0"};
222+
char*embedding[3]= {
223+
"","-e",
224+
/* no commas between the next 4 please. They are supposed to be one string
225+
*/
226+
"require Safe; SPI::bootstrap();"
227+
"sub ::mksafefunc { my $x = new Safe; $x->permit_only(':default');"
228+
"$x->share(qw[&elog &DEBUG &NOTICE &NOIND &ERROR]);"
229+
" return $x->reval(qq[sub { $_[0] }]); }"
230+
};
223231

224232
plperl_safe_interp=perl_alloc();
225233
if (!plperl_safe_interp)
@@ -302,16 +310,19 @@ plperl_call_handler(FmgrInfo *proinfo,
302310
**********************************************************************/
303311
static
304312
SV*
305-
plperl_create_sub(SV*s)
313+
plperl_create_sub(char*s)
306314
{
307315
dSP;
308316

309317
SV*subref=NULL;
318+
intcount;
310319

311320
ENTER;
312321
SAVETMPS;
313322
PUSHMARK(SP);
314-
perl_eval_sv(s,G_SCALAR |G_EVAL |G_KEEPERR);
323+
XPUSHs(sv_2mortal(newSVpv(s,0)));
324+
PUTBACK;
325+
count=perl_call_pv("mksafefunc",G_SCALAR |G_EVAL |G_KEEPERR);
315326
SPAGAIN;
316327

317328
if (SvTRUE(GvSV(errgv)))
@@ -323,6 +334,10 @@ plperl_create_sub(SV * s)
323334
elog(ERROR,"creation of function failed : %s",SvPV(GvSV(errgv),na));
324335
}
325336

337+
if (count!=1) {
338+
elog(ERROR,"creation of function failed - no return from mksafefunc");
339+
}
340+
326341
/*
327342
* need to make a deep copy of the return. it comes off the stack as a
328343
* temporary.
@@ -357,7 +372,6 @@ plperl_create_sub(SV * s)
357372
*
358373
**********************************************************************/
359374

360-
externvoidboot_DynaLoader_((CV*cv));
361375
externvoidboot_Opcode_((CV*cv));
362376
externvoidboot_SPI_((CV*cv));
363377

@@ -366,7 +380,6 @@ plperl_init_shared_libs(void)
366380
{
367381
char*file=__FILE__;
368382

369-
newXS("DynaLoader::bootstrap",boot_DynaLoader,file);
370383
newXS("Opcode::bootstrap",boot_Opcode,file);
371384
newXS("SPI::bootstrap",boot_SPI,file);
372385
}
@@ -492,8 +505,6 @@ plperl_func_handler(FmgrInfo *proinfo,
492505
HeapTupletypeTup;
493506
Form_pg_procprocStruct;
494507
Form_pg_typetypeStruct;
495-
SV*proc_internal_def;
496-
charproc_internal_args[4096];
497508
char*proc_source;
498509

499510
/************************************************************
@@ -550,7 +561,6 @@ plperl_func_handler(FmgrInfo *proinfo,
550561
* of all procedure arguments
551562
************************************************************/
552563
prodesc->nargs=proinfo->fn_nargs;
553-
proc_internal_args[0]='\0';
554564
for (i=0;i<proinfo->fn_nargs;i++)
555565
{
556566
typeTup=SearchSysCacheTuple(TYPEOID,
@@ -584,23 +594,12 @@ plperl_func_handler(FmgrInfo *proinfo,
584594
************************************************************/
585595
proc_source=textout(&(procStruct->prosrc));
586596

587-
/*
588-
* the string has been split for readbility. please don't put
589-
* commas between them. Hope everyone is ANSI
590-
*/
591-
proc_internal_def=newSVpvf(
592-
"$::x = new Safe;"
593-
"$::x->permit_only(':default');"
594-
"$::x->share(qw[&elog &DEBUG &NOTICE &NOIND &ERROR]);"
595-
"use strict;"
596-
"return $::x->reval( q[ sub { %s } ]);",proc_source);
597-
598-
pfree(proc_source);
599597

600598
/************************************************************
601599
* Create the procedure in the interpreter
602600
************************************************************/
603-
prodesc->reference=plperl_create_sub(proc_internal_def);
601+
prodesc->reference=plperl_create_sub(proc_source);
602+
pfree(proc_source);
604603
if (!prodesc->reference)
605604
{
606605
free(prodesc->proname);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp