Subject: | [PATCH] PerlTK encGlue.c memory corruption |
Date: | Wed, 24 Jan 2007 10:37:27 -0500 (EST) |
To: | bug-Tk [...] rt.cpan.org |
From: | mwelinder [...] gmail.com (Morten Welinder) |
there is a systematic problem in Tk-804.027's encGlue.c that is causing
memory corruption. See for example
http://www.arcknowledge.com/gmane.comp.lang.perl.tk/2006-07/msg00001.html
The problem is that "dSP" is declared early and that the stack can relocate
between the declaration and the use of the stack. This can happen, for example,
when a call to GetSystemEncoding ends up calling the perl level.
One solution is to sprinkle a few SPAGAIN calls around as in the patch below.
I hope I got them all.
This bug also causes numerous test failures on, for example, Solaris 2.8 with
Perl 5.8.8.
Morten
--- /home/welinder/encGlue.c Wed Jan 24 09:28:48 2007
+++ /usr/local/src/perl/mods-5.8.8/Tk-804.027/encGlue.c Wed Jan 24 09:31:10 2007
@@ -723,6 +723,7 @@
{
sv_setpvn(stmp,s,len);
}
+ SPAGAIN;
PUSHMARK(sp);
XPUSHs(PerlEncObj(encoding));
XPUSHs(stmp);
@@ -830,6 +831,7 @@
if (srcLen)
{
int count;
+ SPAGAIN;
ENTER;
SAVETMPS;
PUSHMARK(sp);
@@ -880,6 +882,7 @@
STRLEN len;
if (!encoding)
encoding = GetSystemEncoding();
+ SPAGAIN;
ENTER;
SAVETMPS;
if (!src)
@@ -895,6 +898,7 @@
#endif
srcLen = strlen(src);
}
+ SPAGAIN;
PUSHMARK(sp);
XPUSHs(PerlEncObj(encoding));
sv = newSV(srcLen);