New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
calling C function perl_clone of libperl causes segfault in perl 5.22 and and 5.24 but fine on perl 5.20 #15917
Comments
From mitch.capper@gmail.comFor using perl in C++ programs unfortunately a simple call to perl_clone ============Backtrace============== ===========Repro Details=========== You can use these commands in a container like: ============= For 5.24 ============ apt-get update && apt-get install -y lbzip2 zlibc libbz2-dev wget ============= For 5.20 ============ wget ============= perlbug -d for 5.20.0 ============ Flags: Site configuration information for perl 5.20.0: Configured by root at Tue Mar 7 18:44:42 UTC 2017. Summary of my perl5 (revision 5 version 20 subversion 0) configuration: Platform: @INC for perl 5.20.0: Environment for perl 5.20.0: Flags: Site configuration information for perl 5.24.1: Configured by root at Tue Mar 7 19:37:15 UTC 2017. Summary of my perl5 (revision 5 version 24 subversion 1) configuration: Platform: @INC for perl 5.24.1: Environment for perl 5.24.1: --------------1.40.perlbug #include <EXTERN.h> void main(){ // apt-get update && apt-get install build-essential libperl-dev gdb --------------1.40.perlbug-- ~mitch |
From mitch.capper@gmail.com#include <EXTERN.h>
#include <perl.h>
void main(){
PerlInterpreter *my_perl;
if (!(my_perl = perl_alloc())) {
printf("Could not allocate perl interpreter\n");
}
perl_construct(my_perl);
PerlInterpreter *perl2 = perl_clone(my_perl, CLONEf_COPY_STACKS | CLONEf_KEEP_PTR_TABLE);
printf("ALL FINE\n");
}
// apt-get update && apt-get install build-essential libperl-dev gdb
// zesty: gcc -g test.c -I/usr/lib/x86_64-linux-gnu/perl/5.24.1/CORE/ -lperl && ./a.out
// xenial/yakkety (yakkety might be 5.22.2): gcc -g test.c -I/usr/lib/x86_64-linux-gnu/perl/5.22.1/CORE/ -lperl && ./a.out
// trusty: gcc -g test.c -I/usr/lib/perl/5.18.2/CORE/ -lperl && ./a.out
|
From @iabynOn Tue, Mar 07, 2017 at 11:51:38AM -0800, Mitch Capper wrote:
Your test program allocates and constructs a perl interpreter, but *doesn't* Some of the stuff that perl_clone() expects to be in place only happens Do you have a persuasive use case for calling perl_clone() on an "empty" For porters: I reproduced this by building blead with threads and $ cc -o test -I . -DPERL_CORE -D_REENTRANT -D_GNU_SOURCE -DDEBUGGING -ggdb -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -std=c89 -g -Wall -Werror=declaration-after-statement -Wextra -Wc++-compat -Wwrite-strings -L. -lperl ~/tmp/test.c $ LD_LIBRARY_PATH=. ./test where ~/tmp/test.c looks like the following. Uncommenting the perl_parse() #include <EXTERN.h> int main(int argc, char **argv){ /* perl2 = perl_clone(my_perl, CLONEf_COPY_STACKS | CLONEf_KEEP_PTR_TABLE); Perl_croak_nocontext("ALL FINE\n"); -- |
The RT System itself - Status changed from 'new' to 'open' |
From mitch.capper+bit@gmail.comI apologize I have oversimplified the use case here from the FreeSWITCH code to try and make the test case more concise. Their use of mod_perl (https://freeswitch.org/stash/projects/FS/repos/freeswitch/browse/src/mod/languages/mod_perl/mod_perl.c) does immediately call perl_parse after perl_construct so this must be trigged by something else. It also only happens on 5.22 and newer. I will work to update the test case with a better implementation of how FS is calling it that still repros shortly. In the mean time, if obvious, here is the BT from FreeSWITCH when it crashes: Thread 34 "freeswitch" received signal SIGSEGV, Segmentation fault. |
From mitch.capper+bit@gmail.comOk tracked down the problem if an empty string is past after -e it segfaults: #include <EXTERN.h> int main(int argc, char **argv){ PL_exit_flags |= PERL_EXIT_DESTRUCT_END; perl2 = perl_clone(my_perl, CLONEf_COPY_STACKS | CLONEf_KEEP_PTR_TABLE); This makes some sense given -e's meaning we should be able to easily work around for FS but not sure if the change of behavior is expected or not. |
From @tonycozOn Wed, Mar 22, 2017 at 10:50:43AM -0700, Mitch Capper via RT wrote:
The argv array requires a NULL at the end: static char *embedding[] = { "", "-e", "", NULL }; though I don't know if this is the cause of the failure you're seeing. Tony |
From mitch.capper+bit@gmail.comOk so technically still segfaults, but does spit out an error: if you do: #include <EXTERN.h> int main(int argc, char **argv){ PL_exit_flags |= PERL_EXIT_DESTRUCT_END; perl2 = perl_clone(my_perl, CLONEf_COPY_STACKS | CLONEf_KEEP_PTR_TABLE); |
From mitch.capper+bit@gmail.comSorry and to clarify similarly: |
From @iabynOn Wed, Mar 22, 2017 at 05:45:37PM -0700, Mitch Capper via RT wrote:
Yes, but you're now calling perl_clone after a parse error. Strictly Again, show me a valid use case for calling perl_clone() in such -- |
From mitch.capper+bit@gmail.comNo problem, we have a work-around for our use and the function changes it seems are a non issue so this can be closed. |
@iabyn - Status changed from 'open' to 'rejected' |
Migrated from rt.perl.org#130949 (status was 'rejected')
Searchable as RT130949$
The text was updated successfully, but these errors were encountered: