From: Nicholas Clark Date: Mon, 25 Mar 2013 12:06:09 +0000 (+0100) Subject: xs_init() must pass a static char* when creating &DynaLoader::boot_DynaLoader. X-Git-Tag: v5.17.11~51 X-Git-Url: https://perl5.git.perl.org/perl5.git/commitdiff_plain/1b77350017006d9e581d4eda49c59b68e408f51b?ds=sidebyside xs_init() must pass a static char* when creating &DynaLoader::boot_DynaLoader. newXS() assumes that the passed pointer to the filename is in static storage, or otherwise will outlive the PVCV that it is about to create, and hence that it's safe to copy the pointer, not the value, to CvFILE. Hence xs_init() must not use an auto array to "store" the filename, as that will be on the stack, and becomes invalid as soon as xs_init() returns. The analogous bug fix was made in universal.c by commit 157e3fc8c802010d in Feb 2006. Spotted by compiling for ithreads with gcc 4.8.0's ASAN and running dist/B-Deparse/t/deparse.t --- diff --git a/minimod.pl b/minimod.pl index a5bd172..a59b7f2 100644 --- a/minimod.pl +++ b/minimod.pl @@ -71,7 +71,7 @@ sub writemain{ my ($tail1,$tail2,$tail3) = ( $tail =~ /\A(.*{\s*\n)(.*\n)(\s*\}.*)\Z/s ); print $tail1; - print "\tconst char file[] = __FILE__;\n"; + print "\tstatic const char file[] = __FILE__;\n"; print "\tdXSUB_SYS;\n" if $] > 5.002; print $tail2;