File tree Expand file tree Collapse file tree 4 files changed +23
-9
lines changed Expand file tree Collapse file tree 4 files changed +23
-9
lines changed Original file line number Diff line number Diff line change @@ -72,11 +72,11 @@ perlchunks.h: $(PERLCHUNKS)
7272
7373all : all-lib
7474
75- SPI.c : SPI.xs
75+ SPI.c : SPI.xs plperl_helpers.h
7676 @if [ x" $( perl_privlibexp) " = x" " ]; then echo " configure switch --with-perl was not specified." ; exit 1; fi
7777 $(PERL ) $(XSUBPPDIR ) /ExtUtils/xsubpp -typemap $(perl_privlibexp ) /ExtUtils/typemap $< > $@
7878
79- Util.c : Util.xs
79+ Util.c : Util.xs plperl_helpers.h
8080 @if [ x" $( perl_privlibexp) " = x" " ]; then echo " configure switch --with-perl was not specified." ; exit 1; fi
8181 $(PERL ) $(XSUBPPDIR ) /ExtUtils/xsubpp -typemap $(perl_privlibexp ) /ExtUtils/typemap $< > $@
8282
Original file line number Diff line number Diff line change @@ -58,3 +58,7 @@ select uses_global();
5858 uses_global worked
5959(1 row)
6060
61+ -- make sure we don't choke on readonly values
62+ do language plperl $$ elog(NOTICE, ${^TAINT}); $$;
63+ NOTICE: 0
64+ CONTEXT: PL/Perl anonymous code block
Original file line number Diff line number Diff line change @@ -47,28 +47,35 @@ sv2cstr(SV *sv)
4747{
4848 char * val , * res ;
4949 STRLEN len ;
50- SV * nsv ;
5150
5251 /*
5352 * get a utf8 encoded char * out of perl. *note* it may not be valid utf8!
5453 *
5554 * SvPVutf8() croaks nastily on certain things, like typeglobs and
5655 * readonly objects such as $^V. That's a perl bug - it's not supposed to
57- * happen. To avoid crashing the backend, we make a copy of the
58- * sv before passing it to SvPVutf8(). The copy is garbage collected
56+ * happen. To avoid crashing the backend, we make a copy of the sv before
57+ * passing it to SvPVutf8(). The copy is garbage collected
5958 * when we're done with it.
6059 */
61- nsv = newSVsv (sv );
62- val = SvPVutf8 (nsv , len );
60+ if (SvREADONLY (sv ) ||
61+ isGV_with_GP (sv ) ||
62+ (SvTYPE (sv ) > SVt_PVLV && SvTYPE (sv ) != SVt_PVFM ))
63+ sv = newSVsv (sv );
64+ else
65+ /* increase the reference count so we cant just SvREFCNT_dec() it when
66+ * we are done */
67+ SvREFCNT_inc (sv );
68+
69+ val = SvPVutf8 (sv , len );
6370
6471 /*
6572 * we use perl's length in the event we had an embedded null byte to ensure
6673 * we error out properly
6774 */
68- res = utf_u2e (val , len );
75+ res = utf_u2e (val , len );
6976
7077 /* safe now to garbage collect the new SV */
71- SvREFCNT_dec (nsv );
78+ SvREFCNT_dec (sv );
7279
7380 return res ;
7481}
Original file line number Diff line number Diff line change @@ -43,3 +43,6 @@ create or replace function uses_global() returns text language plperl as $$
4343$$;
4444
4545select uses_global();
46+
47+ -- make sure we don't choke on readonly values
48+ do language plperl $$ elog(NOTICE, ${^TAINT}); $$;
You can’t perform that action at this time.
0 commit comments