bug: core dumped if the Cpanel::JSON::XS module is used.
xiaocang opened this issue · 4 comments
xiaocang commented
reproduction
t.pl
use Cpanel::JSON::XS;
compile with perlcc and execute:
$ /usr/local/perl/bin/perlcc -o t t.pl
$ ./t
Segmentation fault (core dumped)
backtrace here:
(gdb) bt
#0 XS_Cpanel__JSON__XS_END (my_perl=0x52f2a0, cv=<optimized out>) at XS.xs:4630
#1 0x00007ffff7eae11f in Perl_pp_entersub () from /usr/local/perl/lib/perl5/CORE/libperl.so
#2 0x00007ffff7e265c7 in Perl_call_sv () from /usr/local/perl/lib/perl5/CORE/libperl.so
#3 0x00007ffff7e28ac5 in Perl_call_list () from /usr/local/perl/lib/perl5/CORE/libperl.so
#4 0x00007ffff7e2a675 in perl_destruct () from /usr/local/perl/lib/perl5/CORE/libperl.so
#5 0x0000000000494e79 in main ()
perlcc version
perlcc 2.24, B-C-1.57 built for /usr/local/perl/bin/perl x86_64-linux-thread-multi
perl version
$ /usr/local/perl/bin/perl -V
Summary of my perl5 (revision 5 version 24 subversion 4) configuration:
Platform:
osname=linux, osvers=5.11.15-100.fc32.x86_64, archname=x86_64-linux-thread-multi
uname='linux xxx 5.11.15-100.fc32.x86_64 #1 smp fri apr 16 14:19:43 utc 2021 x86_64 x86_64 x86_64 gnulinux '
config_args='-des -Doptimize=-g -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -Dlddlflags=-shared -g -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -Dmyhostname=xxx -Dcc=ccache gcc -Dcf_by=orinc -Dinstallprefix=/usr/local/perl -Dprefix=/usr/local/perl -Darchname=x86_64-linux -Dvendorprefix=/usr/local/perl -Dsiteprefix=/usr/local/perl -Dprivlib=/usr/local/perl/share/perl5 -Darchlib=/usr/local/perl/lib/perl5 -Duseshrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_dosuid=n -Dd_semctl_semun -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl=n -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr -Dd_gethostent_r_proto -Ud_endhostent_r_proto -Ud_sethostent_r_proto -Ud_endprotoent_r_proto -Ud_setprotoent_r_proto -Ud_endservent_r_proto -Ud_setservent_r_proto -Dscriptdir=/usr/local/perl/bin'
hint=recommended, useposix=true, d_sigaction=define
useithreads=define, usemultiplicity=define
use64bitint=define, use64bitall=define, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='ccache gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fpcc-struct-return -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-g -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection',
cppflags='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fpcc-struct-return -pipe -fstack-protector-strong -I/usr/local/include -D__GNUC__'
ccversion='', gccversion='10.2.1 20201125 (Red Hat 10.2.1-9)', gccosandvers=''
intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678, doublekind=3
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16, longdblkind=3
ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='ccache gcc', ldflags =' -fstack-protector-strong -L/usr/local/lib'
libpth=/usr/local/lib /usr/lib /lib/../lib64 /usr/lib/../lib64 /lib /lib64 /usr/lib64 /usr/local/lib64
libs=-lpthread -ldl -lm -lcrypt -lutil -lc
perllibs=-lpthread -ldl -lm -lcrypt -lutil -lc
libc=libc-2.31.so, so=so, useshrplib=true, libperl=libperl.so
gnulibc_version='2.31'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/local/perl/lib/perl5/CORE'
cccdlflags='-fPIC', lddlflags='-shared -g -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -L/usr/local/lib'
Characteristics of this binary (from libperl):
Compile-time options: HAS_TIMES MULTIPLICITY PERLIO_LAYERS
PERL_COPY_ON_WRITE PERL_DONT_CREATE_GVSV
PERL_HASH_FUNC_ONE_AT_A_TIME_HARD
PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP
PERL_PRESERVE_IVUV USE_64_BIT_ALL USE_64_BIT_INT
USE_ITHREADS USE_LARGE_FILES USE_LOCALE
USE_LOCALE_COLLATE USE_LOCALE_CTYPE
USE_LOCALE_NUMERIC USE_LOCALE_TIME USE_PERLIO
USE_PERL_ATOF USE_REENTRANT_API
Built under linux
Compiled at Feb 7 2021 00:00:00
@INC:
/usr/local/perl/lib/site_perl/5.24.4/x86_64-linux-thread-multi
/usr/local/perl/lib/site_perl/5.24.4
/usr/local/perl/lib/vendor_perl/5.24.4/x86_64-linux-thread-multi
/usr/local/perl/lib/vendor_perl/5.24.4
/usr/local/perl/lib/perl5
/usr/local/perl/share/perl5
agentzh commented
@rurban It seems the following patch for the perl 5.24.4 core fixes this. Will you have a quick look at it? Many thanks!
--- perl-5.24.4/inline.h 2018-03-23 12:37:49.000000000 -0700
+++ perl-5.24.4-patched/inline.h 2022-05-02 22:25:33.931000000 -0700
@@ -170,11 +170,13 @@ S_SvREFCNT_dec(pTHX_ SV *sv)
PERL_STATIC_INLINE void
S_SvREFCNT_dec_NN(pTHX_ SV *sv)
{
- U32 rc = SvREFCNT(sv);
- if (LIKELY(rc > 1))
- SvREFCNT(sv) = rc - 1;
- else
- Perl_sv_free2(aTHX_ sv, rc);
+ if (LIKELY(sv != NULL)) {
+ U32 rc = SvREFCNT(sv);
+ if (LIKELY(rc > 1))
+ SvREFCNT(sv) = rc - 1;
+ else
+ Perl_sv_free2(aTHX_ sv, rc);
+ }
}
PERL_STATIC_INLINE void
rurban commented
Please use https://github.com/rurban/Cpanel-JSON-XS/tree/gh438-compiler.
The END method was broken
xiaocang commented
Please use https://github.com/rurban/Cpanel-JSON-XS/tree/gh438-compiler
Hi @rurban, Maybe you forgot to push this branch?
rurban commented
No, it's already merged. DESTROY had similar issues.
new release with all the fixes soon