Skip to content

Commit

Permalink
Fix UTF-8 double encoding issues (RT#52400)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobtfish committed Jan 10, 2010
1 parent ed436fe commit c9234f8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions perl/ChangeLog
@@ -1,3 +1,6 @@
o Fix UTF-8 double encoding when FCGI is passed octets by downgrading
them into bytes correctly. Fixes RT#52400 <chansen@cpan.org>

Version 0.68 -- 31 Dec 2009 <mst@shadowcat.co.uk> Matt S Trout
o No changes since the previous development release.

Expand Down
17 changes: 15 additions & 2 deletions perl/FCGI.XL
Expand Up @@ -543,7 +543,12 @@ PRINT(stream, ...)
CODE:
for (n = 1; n < items; ++n) {
STRLEN len;
register char *tmps = (char *)SvPV(ST(n),len);
register char *tmps;
#ifdef DO_UTF8
if (DO_UTF8(ST(n)) && !sv_utf8_downgrade(ST(n), 1))
croak("Wide character in FCGI::Stream::PRINT");
#endif
tmps = (char *)SvPV(ST(n),len);
FCGX_PutStr(tmps, len, stream);
}
if (SvTRUEx(perl_get_sv("|", FALSE)))
Expand All @@ -563,6 +568,10 @@ WRITE(stream, bufsv, len, ...)

CODE:
offset = (items == 4) ? (int)SvIV(ST(3)) : 0;
#ifdef DO_UTF8
if (DO_UTF8(bufsv) && !sv_utf8_downgrade(bufsv, 1))
croak("Wide character in FCGI::Stream::WRITE");
#endif
buf = SvPV(bufsv, blen);
if (offset < 0) offset += blen;
if (len > blen - offset)
Expand All @@ -572,7 +581,7 @@ WRITE(stream, bufsv, len, ...)
ST(0) = &PL_sv_undef;
else {
ST(0) = sv_newmortal();
sv_setpvf(ST(0), "%c", n);
sv_setiv(ST(0), n);
}

int
Expand All @@ -587,6 +596,10 @@ READ(stream, bufsv, len, ...)

CODE:
offset = (items == 4) ? (int)SvIV(ST(3)) : 0;
#ifdef DO_UTF8
if (DO_UTF8(bufsv) && !sv_utf8_downgrade(bufsv, 1))
croak("Wide character in FCGI::Stream::READ");
#endif
if (! SvOK(bufsv))
sv_setpvn(bufsv, "", 0);
buf = SvGROW(bufsv, len+offset+1);
Expand Down

0 comments on commit c9234f8

Please sign in to comment.