Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1c4c741

Browse files
committed
Check values passed back from PLPerl to the database, via function return,
trigger tuple modification or SPI call, to ensure they are valid in the server encoding. Along the way, replace uses of SvPV(foo, PL_na) with SvPV_nolen(foo) as recommended in the perl docs. Bug report from Hannu Krosing.
1 parent 305e85b commit 1c4c741

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

src/pl/plperl/plperl.c

Lines changed: 32 additions & 14 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.157 2009/12/31 19:41:37 tgl Exp $
4+
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.158 2010/01/04 20:29:59 adunstan Exp $
55
*
66
**********************************************************************/
77

@@ -630,7 +630,13 @@ plperl_build_tuple_result(HV *perlhash, AttInMetadata *attinmeta)
630630
errmsg("Perl hash contains nonexistent column \"%s\"",
631631
key)));
632632
if (SvOK(val))
633-
values[attn - 1] = SvPV(val, PL_na);
633+
{
634+
char * aval;
635+
636+
aval = SvPV_nolen(val);
637+
pg_verifymbstr(aval, strlen(aval), false);
638+
values[attn - 1] = aval;
639+
}
634640
}
635641
hv_iterinit(perlhash);
636642

@@ -829,8 +835,12 @@ plperl_modify_tuple(HV *hvTD, TriggerData *tdata, HeapTuple otup)
829835
atttypmod = tupdesc->attrs[attn - 1]->atttypmod;
830836
if (SvOK(val))
831837
{
838+
char * aval;
839+
840+
aval = SvPV_nolen(val);
841+
pg_verifymbstr(aval,strlen(aval), false);
832842
modvalues[slotsused] = InputFunctionCall(&finfo,
833-
SvPV(val, PL_na),
843+
aval,
834844
typioparam,
835845
atttypmod);
836846
modnulls[slotsused] = ' ';
@@ -1125,7 +1135,7 @@ plperl_create_sub(const char *proname, const char *s, bool trusted)
11251135
LEAVE;
11261136
ereport(ERROR,
11271137
(errcode(ERRCODE_SYNTAX_ERROR),
1128-
errmsg("%s", strip_trailing_ws(SvPV(ERRSV, PL_na)))));
1138+
errmsg("%s", strip_trailing_ws(SvPV_nolen(ERRSV)))));
11291139
}
11301140

11311141
/*
@@ -1253,7 +1263,7 @@ plperl_call_perl_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo)
12531263
LEAVE;
12541264
/* XXX need to find a way to assign an errcode here */
12551265
ereport(ERROR,
1256-
(errmsg("%s", strip_trailing_ws(SvPV(ERRSV, PL_na)))));
1266+
(errmsg("%s", strip_trailing_ws(SvPV_nolen(ERRSV)))));
12571267
}
12581268

12591269
retval = newSVsv(POPs);
@@ -1309,7 +1319,7 @@ plperl_call_perl_trigger_func(plperl_proc_desc *desc, FunctionCallInfo fcinfo,
13091319
LEAVE;
13101320
/* XXX need to find a way to assign an errcode here */
13111321
ereport(ERROR,
1312-
(errmsg("%s", strip_trailing_ws(SvPV(ERRSV, PL_na)))));
1322+
(errmsg("%s", strip_trailing_ws(SvPV_nolen(ERRSV)))));
13131323
}
13141324

13151325
retval = newSVsv(POPs);
@@ -1467,8 +1477,8 @@ plperl_func_handler(PG_FUNCTION_ARGS)
14671477
perlret = array_ret;
14681478
}
14691479

1470-
val = SvPV(perlret, PL_na);
1471-
1480+
val = SvPV_nolen(perlret);
1481+
pg_verifymbstr(val, strlen(val), false);
14721482
retval = InputFunctionCall(&prodesc->result_in_func, val,
14731483
prodesc->result_typioparam, -1);
14741484
}
@@ -1550,7 +1560,7 @@ plperl_trigger_handler(PG_FUNCTION_ARGS)
15501560
HeapTuple trv;
15511561
char *tmp;
15521562

1553-
tmp = SvPV(perlret, PL_na);
1563+
tmp = SvPV_nolen(perlret);
15541564

15551565
if (pg_strcasecmp(tmp, "SKIP") == 0)
15561566
trv = NULL;
@@ -2124,8 +2134,8 @@ plperl_return_next(SV *sv)
21242134
sv = plperl_convert_to_pg_array(sv);
21252135
}
21262136

2127-
val = SvPV(sv, PL_na);
2128-
2137+
val = SvPV_nolen(sv);
2138+
pg_verifymbstr(val, strlen(val), false);
21292139
ret = InputFunctionCall(&prodesc->result_in_func, val,
21302140
prodesc->result_typioparam, -1);
21312141
isNull = false;
@@ -2357,7 +2367,7 @@ plperl_spi_prepare(char *query, int argc, SV **argv)
23572367
typIOParam;
23582368
int32 typmod;
23592369

2360-
parseTypeString(SvPV(argv[i], PL_na), &typId, &typmod);
2370+
parseTypeString(SvPV_nolen(argv[i]), &typId, &typmod);
23612371

23622372
getTypeInputInfo(typId, &typInput, &typIOParam);
23632373

@@ -2516,8 +2526,12 @@ plperl_spi_exec_prepared(char *query, HV *attr, int argc, SV **argv)
25162526
{
25172527
if (SvOK(argv[i]))
25182528
{
2529+
char *val;
2530+
2531+
val = SvPV_nolen(argv[i]);
2532+
pg_verifymbstr(val, strlen(val), false);
25192533
argvalues[i] = InputFunctionCall(&qdesc->arginfuncs[i],
2520-
SvPV(argv[i], PL_na),
2534+
val,
25212535
qdesc->argtypioparams[i],
25222536
-1);
25232537
nulls[i] = ' ';
@@ -2647,8 +2661,12 @@ plperl_spi_query_prepared(char *query, int argc, SV **argv)
26472661
{
26482662
if (SvOK(argv[i]))
26492663
{
2664+
char *val;
2665+
2666+
val = SvPV_nolen(argv[i]);
2667+
pg_verifymbstr(val, strlen(val), false);
26502668
argvalues[i] = InputFunctionCall(&qdesc->arginfuncs[i],
2651-
SvPV(argv[i], PL_na),
2669+
val,
26522670
qdesc->argtypioparams[i],
26532671
-1);
26542672
nulls[i] = ' ';

0 commit comments

Comments
 (0)