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

Commit6e73b50

Browse files
committed
Workaround for perl problem where evaluating UTF8 regexes can cause
implicit loading of modules, thereby breaking Safe rules.We compile and call a tiny perl function on trusted interpreter init, after whichthe problem does not occur.
1 parent895a94d commit6e73b50

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

‎src/pl/plperl/GNUmakefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Makefile for PL/Perl
2-
# $PostgreSQL: pgsql/src/pl/plperl/GNUmakefile,v 1.31 2007/07/25 10:17:46 mha Exp $
2+
# $PostgreSQL: pgsql/src/pl/plperl/GNUmakefile,v 1.32 2007/12/01 15:20:34 adunstan Exp $
33

44
subdir = src/pl/plperl
55
top_builddir = ../../..
@@ -27,6 +27,7 @@ override CFLAGS += -Wno-comment
2727
endif
2828

2929
overrideCPPFLAGS := -I$(srcdir)$(CPPFLAGS) -I$(perl_archlibexp)/CORE
30+
overrideCFLAGS += -fPIC
3031

3132
rpathdir =$(perl_archlibexp)/CORE
3233

‎src/pl/plperl/plperl.c

Lines changed: 50 additions & 1 deletion
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.132 2007/11/15 22:25:17 momjian Exp $
4+
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.133 2007/12/01 15:20:34 adunstan Exp $
55
*
66
**********************************************************************/
77

@@ -149,6 +149,8 @@ static HV *plperl_spi_execute_fetch_result(SPITupleTable *, int, int);
149149
staticSV*newSVstring(constchar*str);
150150
staticSV**hv_store_string(HV*hv,constchar*key,SV*val);
151151
staticSV**hv_fetch_string(HV*hv,constchar*key);
152+
staticSV*plperl_create_sub(char*proname,char*s,booltrusted);
153+
staticSV*plperl_call_perl_func(plperl_proc_desc*desc,FunctionCallInfofcinfo);
152154

153155
/*
154156
* This routine is a crock, and so is everyplace that calls it. The problem
@@ -504,6 +506,53 @@ plperl_safe_init(void)
504506
else
505507
{
506508
eval_pv(SAFE_OK, FALSE);
509+
if (GetDatabaseEncoding()==PG_UTF8)
510+
{
511+
512+
/*
513+
* Fill in just enough information to set up this perl
514+
* function in the safe container and call it.
515+
* For some reason not entirely clear, it prevents errors that
516+
* can arise from the regex code later trying to load
517+
* utf8 modules.
518+
*/
519+
520+
plperl_proc_descdesc;
521+
FunctionCallInfoDatafcinfo;
522+
FmgrInfooutfunc;
523+
HeapTupletypeTup;
524+
Form_pg_typetypeStruct;
525+
SV*ret;
526+
SV*func;
527+
528+
/* make sure we don't call ourselves recursively */
529+
plperl_safe_init_done= true;
530+
531+
/* compile the function */
532+
func=plperl_create_sub(
533+
"utf8fix",
534+
"return shift =~ /\\xa9/i ? 'true' : 'false' ;",
535+
true);
536+
537+
538+
/* set up to call the function with a single text argument 'a' */
539+
desc.reference=func;
540+
desc.nargs=1;
541+
desc.arg_is_rowtype[0]= false;
542+
fcinfo.argnull[0]= false;
543+
fcinfo.arg[0]=
544+
DatumGetTextP(DirectFunctionCall1(textin,
545+
CStringGetDatum("a")));
546+
typeTup=SearchSysCache(TYPEOID,
547+
TEXTOID,
548+
0,0,0);
549+
typeStruct= (Form_pg_type)GETSTRUCT(typeTup);
550+
fmgr_info(typeStruct->typoutput,&(desc.arg_out_func[0]));
551+
ReleaseSysCache(typeTup);
552+
553+
/* and make the call */
554+
ret=plperl_call_perl_func(&desc,&fcinfo);
555+
}
507556
}
508557

509558
plperl_safe_init_done= true;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp