Skip to content
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

2.0209: test suite fails and new compile time warnings with libxml 2.12.0 #81

Open
kloczek opened this issue Nov 21, 2023 · 9 comments
Open

Comments

@kloczek
Copy link

kloczek commented Nov 21, 2023

Here is build result:

+ /usr/bin/perl Makefile.PL INSTALLDIRS=vendor NO_PACKLIST=1 NO_PERLLOCAL=1 'OPTIMIZE=-O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -Wl,--gc-sections -Wl,--as-needed -flto=auto -flto-partition=none -fuse-linker-plugin -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--build-id=sha1' SKIP_SAX_INSTALL=1
Checking if your kit is complete...
Looks good
'SKIP_SAX_INSTALL' is not a known MakeMaker parameter name.
Generating a Unix-style Makefile
Writing Makefile for XML::LibXML
+ /usr/bin/make -O -j48 V=1 VERBOSE=1
Running Mkbootstrap for LibXML ()
chmod 644 "LibXML.bs"
"/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- LibXML.bs blib/arch/auto/XML/LibXML/LibXML.bs 644
"/usr/bin/perl" "/usr/share/perl5/vendor_perl/ExtUtils/xsubpp"  -typemap '/usr/share/perl5/ExtUtils/typemap' -typemap '/home/tkloczko/rpmbuild/BUILD/XML-LibXML-2.0209/typemap'  Devel.xs > Devel.xsc
mv Devel.xsc Devel.c
cp lib/XML/LibXML/SAX.pod blib/lib/XML/LibXML/SAX.pod
cp LibXML.pod blib/lib/XML/LibXML.pod
cp lib/XML/LibXML/Reader.pm blib/lib/XML/LibXML/Reader.pm
cp lib/XML/LibXML/Number.pm blib/lib/XML/LibXML/Number.pm
cp lib/XML/LibXML/SAX/Builder.pm blib/lib/XML/LibXML/SAX/Builder.pm
cp lib/XML/LibXML/Error.pm blib/lib/XML/LibXML/Error.pm
cp lib/XML/LibXML/Schema.pod blib/lib/XML/LibXML/Schema.pod
cp lib/XML/LibXML/Comment.pod blib/lib/XML/LibXML/Comment.pod
cp lib/XML/LibXML/Namespace.pod blib/lib/XML/LibXML/Namespace.pod
cp lib/XML/LibXML/XPathContext.pm blib/lib/XML/LibXML/XPathContext.pm
cp lib/XML/LibXML/InputCallback.pod blib/lib/XML/LibXML/InputCallback.pod
cp lib/XML/LibXML/Literal.pm blib/lib/XML/LibXML/Literal.pm
cp lib/XML/LibXML/Text.pod blib/lib/XML/LibXML/Text.pod
cp lib/XML/LibXML/RelaxNG.pod blib/lib/XML/LibXML/RelaxNG.pod
cp lib/XML/LibXML/ErrNo.pm blib/lib/XML/LibXML/ErrNo.pm
cp lib/XML/LibXML/SAX.pm blib/lib/XML/LibXML/SAX.pm
cp lib/XML/LibXML/Node.pod blib/lib/XML/LibXML/Node.pod
cp lib/XML/LibXML/Attr.pod blib/lib/XML/LibXML/Attr.pod
cp lib/XML/LibXML/Boolean.pm blib/lib/XML/LibXML/Boolean.pm
cp lib/XML/LibXML/Common.pod blib/lib/XML/LibXML/Common.pod
cp lib/XML/LibXML/Parser.pod blib/lib/XML/LibXML/Parser.pod
cp lib/XML/LibXML/NodeList.pm blib/lib/XML/LibXML/NodeList.pm
cp lib/XML/LibXML/Common.pm blib/lib/XML/LibXML/Common.pm
cp lib/XML/LibXML/SAX/Parser.pm blib/lib/XML/LibXML/SAX/Parser.pm
cp lib/XML/LibXML/ErrNo.pod blib/lib/XML/LibXML/ErrNo.pod
cp LibXML.pm blib/lib/XML/LibXML.pm
cp lib/XML/LibXML/RegExp.pod blib/lib/XML/LibXML/RegExp.pod
cp lib/XML/LibXML/PI.pod blib/lib/XML/LibXML/PI.pod
cp lib/XML/LibXML/DOM.pod blib/lib/XML/LibXML/DOM.pod
cp lib/XML/LibXML/CDATASection.pod blib/lib/XML/LibXML/CDATASection.pod
cp lib/XML/LibXML/Devel.pm blib/lib/XML/LibXML/Devel.pm
cp lib/XML/LibXML/AttributeHash.pm blib/lib/XML/LibXML/AttributeHash.pm
cp lib/XML/LibXML/Document.pod blib/lib/XML/LibXML/Document.pod
cp lib/XML/LibXML/SAX/Generator.pm blib/lib/XML/LibXML/SAX/Generator.pm
cp lib/XML/LibXML/SAX/Builder.pod blib/lib/XML/LibXML/SAX/Builder.pod
cp lib/XML/LibXML/Pattern.pod blib/lib/XML/LibXML/Pattern.pod
cp lib/XML/LibXML/Element.pod blib/lib/XML/LibXML/Element.pod
cp lib/XML/LibXML/Dtd.pod blib/lib/XML/LibXML/Dtd.pod
cp lib/XML/LibXML/Reader.pod blib/lib/XML/LibXML/Reader.pod
cp lib/XML/LibXML/Error.pod blib/lib/XML/LibXML/Error.pod
cp lib/XML/LibXML/DocumentFragment.pod blib/lib/XML/LibXML/DocumentFragment.pod
cp lib/XML/LibXML/XPathContext.pod blib/lib/XML/LibXML/XPathContext.pod
cp lib/XML/LibXML/XPathExpression.pod blib/lib/XML/LibXML/XPathExpression.pod
"/usr/bin/perl" "/usr/share/perl5/vendor_perl/ExtUtils/xsubpp"  -typemap '/usr/share/perl5/ExtUtils/typemap' -typemap '/home/tkloczko/rpmbuild/BUILD/XML-LibXML-2.0209/typemap'  LibXML.xs > LibXML.xsc
mv LibXML.xsc LibXML.c
/usr/bin/gcc -c  -I/usr/include/libxml2  -D_REENTRANT -D_GNU_SOURCE -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -fwrapv -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -Wl,--gc-sections -Wl,--as-needed -flto=auto -flto-partition=none -fuse-linker-plugin -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--build-id=sha1   -DVERSION=\"2.0209\" -DXS_VERSION=\"2.0209\" -fPIC "-I/usr/lib64/perl5/CORE"  -DHAVE_UTF8 xpath.c
/usr/bin/gcc -c  -I/usr/include/libxml2  -D_REENTRANT -D_GNU_SOURCE -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -fwrapv -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -Wl,--gc-sections -Wl,--as-needed -flto=auto -flto-partition=none -fuse-linker-plugin -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--build-id=sha1   -DVERSION=\"2.0209\" -DXS_VERSION=\"2.0209\" -fPIC "-I/usr/lib64/perl5/CORE"  -DHAVE_UTF8 Av_CharPtrPtr.c
/usr/bin/gcc -c  -I/usr/include/libxml2  -D_REENTRANT -D_GNU_SOURCE -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -fwrapv -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -Wl,--gc-sections -Wl,--as-needed -flto=auto -flto-partition=none -fuse-linker-plugin -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--build-id=sha1   -DVERSION=\"2.0209\" -DXS_VERSION=\"2.0209\" -fPIC "-I/usr/lib64/perl5/CORE"  -DHAVE_UTF8 dom.c
dom.c: In function ‘domName’:
dom.c:657:5: warning: case value ‘21’ not in enumerated type ‘xmlElementType’ [-Wswitch]
  657 |     case XML_DOCB_DOCUMENT_NODE :
      |     ^~~~
/usr/bin/gcc -c  -I/usr/include/libxml2  -D_REENTRANT -D_GNU_SOURCE -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -fwrapv -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -Wl,--gc-sections -Wl,--as-needed -flto=auto -flto-partition=none -fuse-linker-plugin -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--build-id=sha1   -DVERSION=\"2.0209\" -DXS_VERSION=\"2.0209\" -fPIC "-I/usr/lib64/perl5/CORE"  -DHAVE_UTF8 perl-libxml-mm.c
perl-libxml-mm.c: In function ‘PmmDumpRegistry’:
perl-libxml-mm.c:142:32: warning: passing argument 2 of ‘xmlHashScan’ from incompatible pointer type [-Wincompatible-pointer-types]
  142 |                 xmlHashScan(r, PmmRegistryDumpHashScanner, NULL);
      |                                ^~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                |
      |                                void (*)(void *, void *, xmlChar *) {aka void (*)(void *, void *, unsigned char *)}
In file included from /usr/include/libxml2/libxml/parser.h:16,
                 from perl-libxml-mm.h:20,
                 from perl-libxml-mm.c:26:
/usr/include/libxml2/libxml/hash.h:209:57: note: expected ‘xmlHashScanner’ {aka ‘void (*)(void *, void *, const unsigned char *)’} but argument is of type ‘void (*)(void *, void *, xmlChar *)’ {aka ‘void (*)(void *, void *, unsigned char *)’}
  209 |                                          xmlHashScanner scan,
      |                                          ~~~~~~~~~~~~~~~^~~~
perl-libxml-mm.c: In function ‘PmmUnregisterProxyNode’:
perl-libxml-mm.c:234:51: warning: passing argument 3 of ‘xmlHashRemoveEntry’ from incompatible pointer type [-Wincompatible-pointer-types]
  234 |         if( xmlHashRemoveEntry(PmmREGISTRY, name, PmmRegistryHashDeallocator) )
      |                                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                   |
      |                                                   void (*)(void *, xmlChar *) {aka void (*)(void *, unsigned char *)}
/usr/include/libxml2/libxml/hash.h:152:61: note: expected ‘xmlHashDeallocator’ {aka ‘void (*)(void *, const unsigned char *)’} but argument is of type ‘void (*)(void *, xmlChar *)’ {aka ‘void (*)(void *, unsigned char *)’}
  152 |                                          xmlHashDeallocator dealloc);
      |                                          ~~~~~~~~~~~~~~~~~~~^~~~~~~
perl-libxml-mm.c: In function ‘PmmCloneProxyNodes’:
perl-libxml-mm.c:301:45: warning: passing argument 2 of ‘xmlHashCopy’ from incompatible pointer type [-Wincompatible-pointer-types]
  301 |         reg_copy = xmlHashCopy(PmmREGISTRY, PmmRegistryHashCopier);
      |                                             ^~~~~~~~~~~~~~~~~~~~~
      |                                             |
      |                                             void * (*)(void *, xmlChar *) {aka void * (*)(void *, unsigned char *)}
/usr/include/libxml2/libxml/hash.h:204:56: note: expected ‘xmlHashCopier’ {aka ‘void * (*)(void *, const unsigned char *)’} but argument is of type ‘void * (*)(void *, xmlChar *)’ {aka ‘void * (*)(void *, unsigned char *)’}
  204 |                                          xmlHashCopier copy);
      |                                          ~~~~~~~~~~~~~~^~~~
perl-libxml-mm.c: In function ‘PmmNewNode’:
perl-libxml-mm.c:334:9: warning: case value ‘21’ not in enumerated type ‘xmlElementType’ [-Wswitch]
  334 |         case XML_DOCB_DOCUMENT_NODE:
      |         ^~~~
perl-libxml-mm.c: In function ‘PmmNodeToSv’:
perl-libxml-mm.c:554:9: warning: case value ‘21’ not in enumerated type ‘xmlElementType’ [-Wswitch]
  554 |         case XML_DOCB_DOCUMENT_NODE:
      |         ^~~~
/usr/bin/gcc -c  -I/usr/include/libxml2  -D_REENTRANT -D_GNU_SOURCE -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -fwrapv -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -Wl,--gc-sections -Wl,--as-needed -flto=auto -flto-partition=none -fuse-linker-plugin -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--build-id=sha1   -DVERSION=\"2.0209\" -DXS_VERSION=\"2.0209\" -fPIC "-I/usr/lib64/perl5/CORE"  -DHAVE_UTF8 Devel.c
/usr/bin/gcc -c  -I/usr/include/libxml2  -D_REENTRANT -D_GNU_SOURCE -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -fwrapv -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -Wl,--gc-sections -Wl,--as-needed -flto=auto -flto-partition=none -fuse-linker-plugin -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--build-id=sha1   -DVERSION=\"2.0209\" -DXS_VERSION=\"2.0209\" -fPIC "-I/usr/lib64/perl5/CORE"  -DHAVE_UTF8 perl-libxml-sax.c
perl-libxml-sax.c: In function ‘PSaxSetDocumentLocator’:
perl-libxml-sax.c:883:9: warning: unused variable ‘empty’ [-Wunused-variable]
  883 |     HV* empty;
      |         ^~~~~
perl-libxml-sax.c: In function ‘PmmSaxError’:
perl-libxml-sax.c:1539:28: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
 1539 |     xmlErrorPtr last_err = xmlCtxtGetLastError( ctxt );
      |                            ^~~~~~~~~~~~~~~~~~~
/usr/bin/gcc -c  -I/usr/include/libxml2  -D_REENTRANT -D_GNU_SOURCE -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -fwrapv -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fdata-sections -ffunction-sections -flto=auto -flto-partition=none -Wl,--gc-sections -Wl,--as-needed -flto=auto -flto-partition=none -fuse-linker-plugin -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--build-id=sha1   -DVERSION=\"2.0209\" -DXS_VERSION=\"2.0209\" -fPIC "-I/usr/lib64/perl5/CORE"  -DHAVE_UTF8 LibXML.c
LibXML.xs: In function ‘LibXML_init_parser’:
LibXML.xs:942:13: warning: ‘xmlKeepBlanksDefault’ is deprecated [-Wdeprecated-declarations]
  942 |             xmlKeepBlanksDefault(0);
      |             ^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/libxml2/libxml/HTMLparser.h:16,
                 from /usr/include/libxml2/libxml/globals.h:18,
                 from LibXML.xs:40:
/usr/include/libxml2/libxml/parser.h:915:17: note: declared here
  915 |                 xmlKeepBlanksDefault    (int val);
      |                 ^~~~~~~~~~~~~~~~~~~~
LibXML.xs:945:13: warning: ‘xmlKeepBlanksDefault’ is deprecated [-Wdeprecated-declarations]
  945 |             xmlKeepBlanksDefault(1);
      |             ^~~~~~~~~~~~~~~~~~~~
/usr/include/libxml2/libxml/parser.h:915:17: note: declared here
  915 |                 xmlKeepBlanksDefault    (int val);
      |                 ^~~~~~~~~~~~~~~~~~~~
LibXML.xs: In function ‘XS_XML__LibXML__end_sax_push’:
LibXML.xs:2668:14: warning: variable ‘real_obj’ set but not used [-Wunused-but-set-variable]
 2668 |         HV * real_obj;
      |              ^~~~~~~~
LibXML.c: In function ‘XS_XML__LibXML__Document_importNode’:
LibXML.c:5395:17: warning: variable ‘dummy’ set but not used [-Wunused-but-set-variable]
 5395 |         int     dummy;
      |                 ^~~~~
LibXML.xs: In function ‘XS_XML__LibXML__Node_unbindNode’:
LibXML.xs:4969:22: warning: unused variable ‘docfrag’ [-Wunused-variable]
 4969 |         ProxyNodePtr docfrag     = NULL;
      |                      ^~~~~~~
LibXML.xs: In function ‘XS_XML__LibXML__Node_addChild’:
LibXML.xs:5036:9: warning: case value ‘21’ not in enumerated type ‘xmlElementType’ [-Wswitch]
 5036 |         case XML_DOCB_DOCUMENT_NODE :
      |         ^~~~
LibXML.xs: In function ‘XS_XML__LibXML__Node__toStringC14N’:
LibXML.xs:5271:20: warning: variable ‘refNode’ set but not used [-Wunused-but-set-variable]
 5271 |         xmlNodePtr refNode            = NULL;
      |                    ^~~~~~~
LibXML.c: In function ‘XS_XML__LibXML__Element_appendTextChild’:
LibXML.c:10373:17: warning: variable ‘nsURI’ set but not used [-Wunused-but-set-variable]
10373 |         SV *    nsURI;
      |                 ^~~~~
LibXML.c: In function ‘XS_XML__LibXML__Attr_toString’:
LibXML.c:11149:17: warning: variable ‘format’ set but not used [-Wunused-but-set-variable]
11149 |         int     format;
      |                 ^~~~~~
rm -f blib/arch/auto/XML/LibXML/LibXML.so
/usr/bin/gcc  -lpthread -shared -Wl,--gc-sections -Wl,--as-needed -flto=auto -flto-partition=none -fuse-linker-plugin -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--build-id=sha1 -L/usr/local/lib -fstack-protector-strong  Av_CharPtrPtr.o Devel.o LibXML.o dom.o perl-libxml-mm.o perl-libxml-sax.o xpath.o  -o blib/arch/auto/XML/LibXML/LibXML.so  \
   -lxml2 -lperl   \

chmod 755 blib/arch/auto/XML/LibXML/LibXML.so

And test suite:

+ /usr/bin/make -O -j48 V=1 VERBOSE=1 test
"/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- LibXML.bs blib/arch/auto/XML/LibXML/LibXML.bs 644
PERL_DL_NONLAZY=1 "/usr/bin/perl" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/00-report-prereqs.t .............................. ok
#
#
# Compiled against libxml2 version: 21200
# Running libxml2 version:          21200
#
t/01basic.t ........................................ ok
t/02parse.t ........................................ ok
t/03doc.t .......................................... ok
t/04node.t ......................................... ok
t/05text.t ......................................... ok
t/06elements.t ..................................... ok
t/07dtd.t .......................................... ok
t/08findnodes.t .................................... ok
t/09xpath.t ........................................ ok
t/10ns.t ........................................... ok
t/11memory.t ....................................... skipped: These tests are for authors only!
t/12html.t ......................................... ok
t/13dtd.t .......................................... ok
t/14sax.t .......................................... ok
t/15nodelist.t ..................................... ok
t/16docnodes.t ..................................... ok
t/17callbacks.t .................................... ok
t/18docfree.t ...................................... ok
t/19die_on_invalid_utf8_rt_58848.t ................. ok
t/19encoding.t ..................................... ok
t/20extras.t ....................................... ok
t/21catalog.t ...................................... ok
t/23rawfunctions.t ................................. ok
t/24c14n.t ......................................... ok
t/25relaxng.t ...................................... ok
t/26schema.t ....................................... ok
t/27new_callbacks_simple.t ......................... ok
t/28new_callbacks_multiple.t ....................... ok
t/29id.t ........................................... ok
t/30keep_blanks.t .................................. ok
t/30xpathcontext.t ................................. ok
t/31xpc_functions.t ................................ ok
t/32xpc_variables.t ................................ ok
t/35huge_mode.t .................................... ok
t/40reader.t ....................................... ok
t/40reader_mem_error.t ............................. ok
t/41xinclude.t ..................................... ok
t/42common.t ....................................... ok
t/43options.t ...................................... ok
Entity: line 1: parser error : Char 0x0 out of allowed range
pseudoroot
          ^
Entity: line 1: parser error : PCDATA invalid Char value 0
pseudoroot
          ^
Entity: line 1: parser error : Char 0x0 out of allowed range
pseudoroot
          ^
Entity: line 1: parser error : PCDATA invalid Char value 0
pseudoroot
          ^
Entity: line 1: parser error : Char 0x0 out of allowed range
pseudoroot
          ^
Entity: line 1: parser error : PCDATA invalid Char value 0
pseudoroot
          ^
Entity: line 1: parser error : Char 0x0 out of allowed range
pseudoroot
          ^
Entity: line 1: parser error : PCDATA invalid Char value 0
pseudoroot
          ^
Entity: line 1: parser error : Char 0x0 out of allowed range
pseudoroot
          ^
Entity: line 1: parser error : PCDATA invalid Char value 0
pseudoroot
          ^
Entity: line 1: parser error : Char 0x0 out of allowed range
pseudoroot
          ^
Entity: line 1: parser error : PCDATA invalid Char value 0
pseudoroot
          ^
:8: parser error : Entity 'b' failed to parse
  <b>&b;</b>
        ^
# Looks like your test exited with 2 before it could output anything.
t/44extent.t .......................................
Dubious, test returned 2 (wstat 512, 0x200)
Failed 7/7 subtests
t/45regex.t ........................................ ok
t/46err_column.t ................................... ok
t/47load_xml_callbacks.t ........................... ok
t/48_gh_pr63_detect_undef_values.t ................. ok
t/48_memleak_rt_83744.t ............................ ok
t/48_reader_undef_warning_on_empty_str_rt106830.t .. ok
t/48_removeChild_crashes_rt_80395.t ................ ok
t/48_replaceNode_DTD_nodes_rT_80521.t .............. ok
t/48_RH5_double_free_rt83779.t ..................... ok
t/48_rt123379_setNamespace.t ....................... ok
t/48_rt55000.t ..................................... ok
t/48_rt93429_recover_2_in_html_parsing.t ........... ok
t/48_SAX_Builder_rt_91433.t ........................ ok
t/48importing_nodes_IDs_rt_69520.t ................. ok
t/49_load_html.t ................................... ok
t/49callbacks_returning_undef.t .................... ok
t/49global_extent.t ................................ ok
t/50devel.t ........................................ ok
t/51_parse_html_string_rt87089.t ................... ok
t/60error_prev_chain.t ............................. ok
t/60struct_error.t ................................. ok
t/61error.t ........................................ ok
t/62overload.t ..................................... ok
t/71overloads.t .................................... ok
t/72destruction.t .................................. ok
t/80registryleak.t ................................. ok
t/90shared_clone_failed_rt_91800.t ................. skipped: optional (set THREAD_TEST=1 to run these tests)
t/90stack.t ........................................ ok
t/90threads.t ...................................... skipped: optional (set THREAD_TEST=1 to run these tests)
t/91unique_key.t ................................... ok
t/cpan-changes.t ................................... skipped: These tests are for authors only!
t/namespace-magic-scalar-rt144415.t ................ ok
t/pod-files-presence.t ............................. skipped: only for AUTHORS
t/pod.t ............................................ skipped: These tests are for authors only!
t/release-kwalitee.t ............................... skipped: These tests are for authors only!
t/style-trailing-space.t ........................... skipped: These tests are for authors only!

Test Summary Report
-------------------
t/44extent.t                                     (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: Bad plan.  You planned 7 tests but ran 0.
Files=77, Tests=2540,  7 wallclock secs ( 0.60 usr  0.25 sys +  5.79 cusr  1.05 csys =  7.69 CPU)
Result: FAIL
Failed 1/77 test programs. 0/2540 subtests failed.
make: *** [Makefile:1127: test_dynamic] Error 255
@ppisar
Copy link
Contributor

ppisar commented Nov 28, 2023

The failing test can be reduced to:

$ cat /tmp/test.t 
use XML::LibXML;

sub handler {
  return join(",",@_);
}

my $parser = XML::LibXML->new({
  expand_entities => 1,
  ext_ent_handler => \&handler,
});

my $doc = $parser->parse_string(<<'EOF');
<?xml version="1.0"?>
<!DOCTYPE foo [
<!ENTITY b SYSTEM "file:///does-not-exist">
]>
<root>&b;</root>
EOF

The output looks like a random string is parsed because the exact invalid bytes changes with each run:

$  perl -Iblib/{lib,arch} /tmp/test.t 
Entity: line 1: parser error : PCDATA invalid Char value 23
g�+�U
 ^
Entity: line 1: parser error : Input is not proper UTF-8, indicate encoding !
Bytes: 0x94 0x2B 0xDD 0x55
g�+�U
  ^
Entity: line 1: parser error : Char 0x0 out of allowed range
g�+�U
      ^
Entity: line 1: parser error : PCDATA invalid Char value 0
g�+�U
      ^
Entity: line 1: parser error : Char 0x0 out of allowed range
g�+�U
       ^
Entity: line 1: parser error : PCDATA invalid Char value 0
g�+�U
       ^
Entity: line 1: parser error : PCDATA invalid Char value 5
g�+�U
        ^
:5: parser error : Entity 'b' failed to parse
<root>&b;</root>
         ^

Valgrind reveals memory errors:

$ valgrind -- perl -Iblib/{lib,arch} /tmp/test.t
==10869== Memcheck, a memory error detector
==10869== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==10869== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info
==10869== Command: perl -Iblib/lib -Iblib/arch /tmp/test.t
==10869==
==10869== Invalid read of size 8
==10869==    at 0x484F2FE: memmove (vg_replace_strmem.c:1410)
==10869==    by 0x5F20916: UnknownInlinedFun (string_fortified.h:29)
==10869==    by 0x5F20916: xmlMemRead (xmlIO.c:2845)
==10869==    by 0x5F28006: xmlParserInputBufferGrow (xmlIO.c:3213)
==10869==    by 0x5EFAE2C: xmlParserGrow (parserInternals.c:537)
==10869==    by 0x5F052B4: xmlDetectEncoding (parserInternals.c:1296)
==10869==    by 0x5EFDD28: xmlParseExternalEntityPrivate.lto_priv.0 (parser.c:12725)
==10869==    by 0x5EF2063: xmlParseReference (parser.c:7369)
==10869==    by 0x5EFDA87: xmlParseContentInternal (parser.c:10268)
==10869==    by 0x5EFF297: xmlParseElement (parser.c:10330)
==10869==    by 0x5EFFEFF: xmlParseDocument (parser.c:11111)
==10869==    by 0x5E48CBF: XS_XML__LibXML__parse_string.lto_priv.0 (LibXML.xs:1755)
==10869==    by 0x49A05A9: Perl_pp_entersub (pp_hot.c:5555)
==10869==  Address 0x6184420 is 0 bytes inside a block of size 25 free'd
==10869==    at 0x4845B2C: free (vg_replace_malloc.c:985)
==10869==    by 0x49A61DD: Perl_sv_clear (sv.c:6919)
==10869==    by 0x49A3DC1: Perl_sv_free2 (sv.c:7244)
==10869==    by 0x49D084E: UnknownInlinedFun (sv_inline.h:715)
==10869==    by 0x49D084E: Perl_free_tmps (scope.c:255)
==10869==    by 0x5E4634C: LibXML_load_external_entity (LibXML.xs:879)
==10869==    by 0x5F276A6: UnknownInlinedFun (xmlIO.c:3977)
==10869==    by 0x5F276A6: xmlLoadExternalEntity (xmlIO.c:3965)
==10869==    by 0x5EF9FA7: xmlCreateEntityParserCtxtInternal (parser.c:13635)
==10869==    by 0x5EFDC58: xmlParseExternalEntityPrivate.lto_priv.0 (parser.c:12681)
==10869==    by 0x5EF2063: xmlParseReference (parser.c:7369)
==10869==    by 0x5EFDA87: xmlParseContentInternal (parser.c:10268)
==10869==    by 0x5EFF297: xmlParseElement (parser.c:10330)
==10869==    by 0x5EFFEFF: xmlParseDocument (parser.c:11111)
==10869==  Block was alloc'd at
==10869==    at 0x484280F: malloc (vg_replace_malloc.c:442)
==10869==    by 0x496BD62: Perl_safesysmalloc (util.c:161)
==10869==    by 0x499EF8F: Perl_sv_grow (sv.c:1376)
==10869==    by 0x49AA63A: Perl_sv_setsv_flags (sv.c:4646)
==10869==    by 0x499A17E: Perl_leave_adjust_stacks (pp_hot.c:5149)
==10869==    by 0x499ED8A: Perl_pp_leavesub (pp_hot.c:5225)
==10869==    by 0x49915D7: Perl_runops_standard (run.c:41)
==10869==    by 0x48D75B9: Perl_call_sv (perl.c:3150)
==10869==    by 0x5E4601C: LibXML_load_external_entity (LibXML.xs:856)
==10869==    by 0x5F276A6: UnknownInlinedFun (xmlIO.c:3977)
==10869==    by 0x5F276A6: xmlLoadExternalEntity (xmlIO.c:3965)
==10869==    by 0x5EF9FA7: xmlCreateEntityParserCtxtInternal (parser.c:13635)
==10869==    by 0x5EFDC58: xmlParseExternalEntityPrivate.lto_priv.0 (parser.c:12681)
==10869==
==10869== Invalid read of size 2
==10869==    at 0x484F350: memmove (vg_replace_strmem.c:1410)
==10869==    by 0x5F20916: UnknownInlinedFun (string_fortified.h:29)
==10869==    by 0x5F20916: xmlMemRead (xmlIO.c:2845)
==10869==    by 0x5F28006: xmlParserInputBufferGrow (xmlIO.c:3213)
==10869==    by 0x5EFAE2C: xmlParserGrow (parserInternals.c:537)
==10869==    by 0x5F052B4: xmlDetectEncoding (parserInternals.c:1296)
==10869==    by 0x5EFDD28: xmlParseExternalEntityPrivate.lto_priv.0 (parser.c:12725)
==10869==    by 0x5EF2063: xmlParseReference (parser.c:7369)
==10869==    by 0x5EFDA87: xmlParseContentInternal (parser.c:10268)
==10869==    by 0x5EFF297: xmlParseElement (parser.c:10330)
==10869==    by 0x5EFFEFF: xmlParseDocument (parser.c:11111)
==10869==    by 0x5E48CBF: XS_XML__LibXML__parse_string.lto_priv.0 (LibXML.xs:1755)
==10869==    by 0x49A05A9: Perl_pp_entersub (pp_hot.c:5555)
==10869==  Address 0x6184430 is 16 bytes inside a block of size 25 free'd
==10869==    at 0x4845B2C: free (vg_replace_malloc.c:985)
==10869==    by 0x49A61DD: Perl_sv_clear (sv.c:6919)
==10869==    by 0x49A3DC1: Perl_sv_free2 (sv.c:7244)
==10869==    by 0x49D084E: UnknownInlinedFun (sv_inline.h:715)
==10869==    by 0x49D084E: Perl_free_tmps (scope.c:255)
==10869==    by 0x5E4634C: LibXML_load_external_entity (LibXML.xs:879)
==10869==    by 0x5F276A6: UnknownInlinedFun (xmlIO.c:3977)
==10869==    by 0x5F276A6: xmlLoadExternalEntity (xmlIO.c:3965)
==10869==    by 0x5EF9FA7: xmlCreateEntityParserCtxtInternal (parser.c:13635)
==10869==    by 0x5EFDC58: xmlParseExternalEntityPrivate.lto_priv.0 (parser.c:12681)
==10869==    by 0x5EF2063: xmlParseReference (parser.c:7369)
==10869==    by 0x5EFDA87: xmlParseContentInternal (parser.c:10268)
==10869==    by 0x5EFF297: xmlParseElement (parser.c:10330)
==10869==    by 0x5EFFEFF: xmlParseDocument (parser.c:11111)
==10869==  Block was alloc'd at
==10869==    at 0x484280F: malloc (vg_replace_malloc.c:442)
==10869==    by 0x496BD62: Perl_safesysmalloc (util.c:161)
==10869==    by 0x499EF8F: Perl_sv_grow (sv.c:1376)
==10869==    by 0x49AA63A: Perl_sv_setsv_flags (sv.c:4646)
==10869==    by 0x499A17E: Perl_leave_adjust_stacks (pp_hot.c:5149)
==10869==    by 0x499ED8A: Perl_pp_leavesub (pp_hot.c:5225)
==10869==    by 0x49915D7: Perl_runops_standard (run.c:41)
==10869==    by 0x48D75B9: Perl_call_sv (perl.c:3150)
==10869==    by 0x5E4601C: LibXML_load_external_entity (LibXML.xs:856)
==10869==    by 0x5F276A6: UnknownInlinedFun (xmlIO.c:3977)
==10869==    by 0x5F276A6: xmlLoadExternalEntity (xmlIO.c:3965)
==10869==    by 0x5EF9FA7: xmlCreateEntityParserCtxtInternal (parser.c:13635)
==10869==    by 0x5EFDC58: xmlParseExternalEntityPrivate.lto_priv.0 (parser.c:12681)
==10869==
==10869== Invalid read of size 2
==10869==    at 0x484F35F: memmove (vg_replace_strmem.c:1410)
==10869==    by 0x5F20916: UnknownInlinedFun (string_fortified.h:29)
==10869==    by 0x5F20916: xmlMemRead (xmlIO.c:2845)
==10869==    by 0x5F28006: xmlParserInputBufferGrow (xmlIO.c:3213)
==10869==    by 0x5EFAE2C: xmlParserGrow (parserInternals.c:537)
==10869==    by 0x5F052B4: xmlDetectEncoding (parserInternals.c:1296)
==10869==    by 0x5EFDD28: xmlParseExternalEntityPrivate.lto_priv.0 (parser.c:12725)
==10869==    by 0x5EF2063: xmlParseReference (parser.c:7369)
==10869==    by 0x5EFDA87: xmlParseContentInternal (parser.c:10268)
==10869==    by 0x5EFF297: xmlParseElement (parser.c:10330)
==10869==    by 0x5EFFEFF: xmlParseDocument (parser.c:11111)
==10869==    by 0x5E48CBF: XS_XML__LibXML__parse_string.lto_priv.0 (LibXML.xs:1755)
==10869==    by 0x49A05A9: Perl_pp_entersub (pp_hot.c:5555)
==10869==  Address 0x6184434 is 20 bytes inside a block of size 25 free'd
==10869==    at 0x4845B2C: free (vg_replace_malloc.c:985)
==10869==    by 0x49A61DD: Perl_sv_clear (sv.c:6919)
==10869==    by 0x49A3DC1: Perl_sv_free2 (sv.c:7244)
==10869==    by 0x49D084E: UnknownInlinedFun (sv_inline.h:715)
==10869==    by 0x49D084E: Perl_free_tmps (scope.c:255)
==10869==    by 0x5E4634C: LibXML_load_external_entity (LibXML.xs:879)
==10869==    by 0x5F276A6: UnknownInlinedFun (xmlIO.c:3977)
==10869==    by 0x5F276A6: xmlLoadExternalEntity (xmlIO.c:3965)
==10869==    by 0x5EF9FA7: xmlCreateEntityParserCtxtInternal (parser.c:13635)
==10869==    by 0x5EFDC58: xmlParseExternalEntityPrivate.lto_priv.0 (parser.c:12681)
==10869==    by 0x5EF2063: xmlParseReference (parser.c:7369)
==10869==    by 0x5EFDA87: xmlParseContentInternal (parser.c:10268)
==10869==    by 0x5EFF297: xmlParseElement (parser.c:10330)
==10869==    by 0x5EFFEFF: xmlParseDocument (parser.c:11111)
==10869==  Block was alloc'd at
==10869==    at 0x484280F: malloc (vg_replace_malloc.c:442)
==10869==    by 0x496BD62: Perl_safesysmalloc (util.c:161)
==10869==    by 0x499EF8F: Perl_sv_grow (sv.c:1376)
==10869==    by 0x49AA63A: Perl_sv_setsv_flags (sv.c:4646)
==10869==    by 0x499A17E: Perl_leave_adjust_stacks (pp_hot.c:5149)
==10869==    by 0x499ED8A: Perl_pp_leavesub (pp_hot.c:5225)
==10869==    by 0x49915D7: Perl_runops_standard (run.c:41)
==10869==    by 0x48D75B9: Perl_call_sv (perl.c:3150)
==10869==    by 0x5E4601C: LibXML_load_external_entity (LibXML.xs:856)
==10869==    by 0x5F276A6: UnknownInlinedFun (xmlIO.c:3977)
==10869==    by 0x5F276A6: xmlLoadExternalEntity (xmlIO.c:3965)
==10869==    by 0x5EF9FA7: xmlCreateEntityParserCtxtInternal (parser.c:13635)
==10869==    by 0x5EFDC58: xmlParseExternalEntityPrivate.lto_priv.0 (parser.c:12681)
==10869==
==10869== Invalid read of size 1
==10869==    at 0x484F380: memmove (vg_replace_strmem.c:1410)
==10869==    by 0x5F20916: UnknownInlinedFun (string_fortified.h:29)
==10869==    by 0x5F20916: xmlMemRead (xmlIO.c:2845)
==10869==    by 0x5F28006: xmlParserInputBufferGrow (xmlIO.c:3213)
==10869==    by 0x5EFAE2C: xmlParserGrow (parserInternals.c:537)
==10869==    by 0x5F052B4: xmlDetectEncoding (parserInternals.c:1296)
==10869==    by 0x5EFDD28: xmlParseExternalEntityPrivate.lto_priv.0 (parser.c:12725)
==10869==    by 0x5EF2063: xmlParseReference (parser.c:7369)
==10869==    by 0x5EFDA87: xmlParseContentInternal (parser.c:10268)
==10869==    by 0x5EFF297: xmlParseElement (parser.c:10330)
==10869==    by 0x5EFFEFF: xmlParseDocument (parser.c:11111)
==10869==    by 0x5E48CBF: XS_XML__LibXML__parse_string.lto_priv.0 (LibXML.xs:1755)
==10869==    by 0x49A05A9: Perl_pp_entersub (pp_hot.c:5555)
==10869==  Address 0x6184436 is 22 bytes inside a block of size 25 free'd
==10869==    at 0x4845B2C: free (vg_replace_malloc.c:985)
==10869==    by 0x49A61DD: Perl_sv_clear (sv.c:6919)
==10869==    by 0x49A3DC1: Perl_sv_free2 (sv.c:7244)
==10869==    by 0x49D084E: UnknownInlinedFun (sv_inline.h:715)
==10869==    by 0x49D084E: Perl_free_tmps (scope.c:255)
==10869==    by 0x5E4634C: LibXML_load_external_entity (LibXML.xs:879)
==10869==    by 0x5F276A6: UnknownInlinedFun (xmlIO.c:3977)
==10869==    by 0x5F276A6: xmlLoadExternalEntity (xmlIO.c:3965)
==10869==    by 0x5EF9FA7: xmlCreateEntityParserCtxtInternal (parser.c:13635)
==10869==    by 0x5EFDC58: xmlParseExternalEntityPrivate.lto_priv.0 (parser.c:12681)
==10869==    by 0x5EF2063: xmlParseReference (parser.c:7369)
==10869==    by 0x5EFDA87: xmlParseContentInternal (parser.c:10268)
==10869==    by 0x5EFF297: xmlParseElement (parser.c:10330)
==10869==    by 0x5EFFEFF: xmlParseDocument (parser.c:11111)
==10869==  Block was alloc'd at
==10869==    at 0x484280F: malloc (vg_replace_malloc.c:442)
==10869==    by 0x496BD62: Perl_safesysmalloc (util.c:161)
==10869==    by 0x499EF8F: Perl_sv_grow (sv.c:1376)
==10869==    by 0x49AA63A: Perl_sv_setsv_flags (sv.c:4646)
==10869==    by 0x499A17E: Perl_leave_adjust_stacks (pp_hot.c:5149)
==10869==    by 0x499ED8A: Perl_pp_leavesub (pp_hot.c:5225)
==10869==    by 0x49915D7: Perl_runops_standard (run.c:41)
==10869==    by 0x48D75B9: Perl_call_sv (perl.c:3150)
==10869==    by 0x5E4601C: LibXML_load_external_entity (LibXML.xs:856)
==10869==    by 0x5F276A6: UnknownInlinedFun (xmlIO.c:3977)
==10869==    by 0x5F276A6: xmlLoadExternalEntity (xmlIO.c:3965)
==10869==    by 0x5EF9FA7: xmlCreateEntityParserCtxtInternal (parser.c:13635)
==10869==    by 0x5EFDC58: xmlParseExternalEntityPrivate.lto_priv.0 (parser.c:12681)
==10869==
==10869==
==10869== HEAP SUMMARY:
==10869==     in use at exit: 4,507,710 bytes in 16,971 blocks
==10869==   total heap usage: 53,270 allocs, 36,299 frees, 10,078,767 bytes allocated
==10869==
==10869== LEAK SUMMARY:
==10869==    definitely lost: 24,148 bytes in 35 blocks
==10869==    indirectly lost: 56,412 bytes in 27 blocks
==10869==      possibly lost: 4,408,443 bytes in 16,872 blocks
==10869==    still reachable: 18,707 bytes in 37 blocks
==10869==                       of which reachable via heuristic:
==10869==                         newarray           : 15,008 bytes in 465 blocks
==10869==         suppressed: 0 bytes in 0 blocks
==10869== Rerun with --leak-check=full to see details of leaked memory
==10869==
==10869== For lists of detected and suppressed errors, rerun with: -s
==10869== ERROR SUMMARY: 6 errors from 4 contexts (suppressed: 0 from 0)

@ppisar
Copy link
Contributor

ppisar commented Nov 28, 2023

It could be a bug in Perl. If the sub handler looks like this:

sub handler {
  my $s;
  $s = join(",", $_[0], undef);
  $s = 'foo';
  return $s;
}

It fails:

Entity: line 1: parser error : Input is not proper UTF-8, indicate encoding !
��3
^
:5: parser error : Entity 'b' failed to parse
<root>&b;</root>
         ^

and valgrind reports the errors. But If you comment out the join() line:

sub handler {
  my $s;
  #$s = join(",", $_[0], undef);
  $s = 'foo';
  return $s;
}

It stops reporting the errors. The trigger is join() called on @_ and undef as the last item.

@ppisar
Copy link
Contributor

ppisar commented Nov 28, 2023

Just a s note that a string produced by join(... ,undef) does not contain NUL bytes. I verified it with Devel::Peek and with dumping the value from LibXML.xs.

@ppisar
Copy link
Contributor

ppisar commented Nov 28, 2023

I think I found it. LibXML_load_external_entity() does:

    if (func != NULL && SvTRUE(*func)) {
        dTHX;
        dSP;

        ENTER;
        SAVETMPS;

        PUSHMARK(SP) ;
        XPUSHs(sv_2mortal(newSVpv((char*)URL, 0)));
        XPUSHs(sv_2mortal(newSVpv((char*)ID, 0)));
        PUTBACK;

        count = call_sv(*func, G_SCALAR | G_EVAL);

        SPAGAIN;

        if (count == 0) {
            croak("external entity handler did not return a value");
        }

        if (SvTRUE(ERRSV)) {
            (void) POPs;
            croak_obj;
        }

        results = POPs;

        results_pv = SvPV(results, results_len);
        input_buf = xmlParserInputBufferCreateMem(
 →                      results_pv,
                        results_len,
                        XML_CHAR_ENCODING_NONE
                        );

        PUTBACK;
        FREETMPS;
        LEAVE;

        return xmlNewIOInputStream(ctxt, input_buf, XML_CHAR_ENCODING_NONE);
    }

A problem is that xmlParserInputBufferCreateMem() does not copy memory pointed by results_pv. It only stores the pointer and expets the memory is valid until destroying the xmlParserInputPtr. But that's not true. results_pv's memory is deallocated with PUTBACK;FREETMPS.

We need to to duplicate the string, or better make results immortal and destroy it with xmlParserInputPtr.

ppisar added a commit to ppisar/perl-XML-LibXML that referenced this issue Nov 28, 2023
With libxml2-2.12.0 and perl-5.38.0 t/44extent.t failed:

    $ perl -Iblib/{lib,arch} ./t/44extent.t
    1..7
    Entity: line 1: parser error : Char 0x0 out of allowed range
    pseudoroot
	      ^
    Entity: line 1: parser error : PCDATA invalid Char value 0
    pseudoroot
	      ^
    [...]
    :8: parser error : Entity 'b' failed to parse
      <b>&b;</b>
	    ^
    # Looks like your test exited with 2 before it could output anything.

The cause was xmlParserInputBufferCreateMem() which does not copy a supplied
buffer. A string returned by the ext_ent_handler handler. As a result, libxml2
read from a deallocated memory parsing random garbage.

This patch fixes it by copying the string with
xmlParserInputBufferPush().

shlomif#81
@nwellnhof
Copy link
Contributor

libxml2 maintainer here. This is a regression in libxml2 and will be fixed soon.

@nwellnhof
Copy link
Contributor

This should be fixed in libxml2 master here: https://gitlab.gnome.org/GNOME/libxml2/-/commit/c2bbeed1fdf500d33ecf9a07213ab6088d255357

The fix will be included in the upcoming 2.12.4 release.

@dilyanpalauzov
Copy link

I confirm that after applying https://gitlab.gnome.org/GNOME/libxml2/-/commit/c2bbeed1fdf500d33ecf9a07213ab6088d255357.patch towards libxml2-2.12.3, and then running make test in XML-LibXML-2.0209 I see

t/43options.t ...................................... ok
t/44extent.t ....................................... ok 
t/45regex.t ........................................ ok

@nwellnhof
Copy link
Contributor

libxml2 2.12.4 containing the fix is available now: https://gitlab.gnome.org/GNOME/libxml2/-/releases/v2.12.4

@kloczek
Copy link
Author

kloczek commented Jan 16, 2024

Just tested perl-XML-LibXML with new ibxml2 2.12.4 and test suite is OK now.
Thank you for your time 👍 😄

+ cd XML-LibXML-2.0209
+ THREAD_TEST=0
+ /usr/bin/make -O -j48 V=1 VERBOSE=1 test
"/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- LibXML.bs blib/arch/auto/XML/LibXML/LibXML.bs 644
PERL_DL_NONLAZY=1 "/usr/bin/perl" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/00-report-prereqs.t .............................. ok
#
#
# Compiled against libxml2 version: 21204
# Running libxml2 version:          21204
#
t/01basic.t ........................................ ok
t/02parse.t ........................................ ok
t/03doc.t .......................................... ok
t/04node.t ......................................... ok
t/05text.t ......................................... ok
t/06elements.t ..................................... ok
t/07dtd.t .......................................... ok
t/08findnodes.t .................................... ok
t/09xpath.t ........................................ ok
t/10ns.t ........................................... ok
t/11memory.t ....................................... skipped: These tests are for authors only!
t/12html.t ......................................... ok
t/13dtd.t .......................................... ok
t/14sax.t .......................................... ok
t/15nodelist.t ..................................... ok
t/16docnodes.t ..................................... ok
t/17callbacks.t .................................... ok
t/18docfree.t ...................................... ok
t/19die_on_invalid_utf8_rt_58848.t ................. ok
t/19encoding.t ..................................... ok
t/20extras.t ....................................... ok
t/21catalog.t ...................................... ok
t/23rawfunctions.t ................................. ok
t/24c14n.t ......................................... ok
t/25relaxng.t ...................................... ok
t/26schema.t ....................................... ok
t/27new_callbacks_simple.t ......................... ok
t/28new_callbacks_multiple.t ....................... ok
t/29id.t ........................................... ok
t/30keep_blanks.t .................................. ok
t/30xpathcontext.t ................................. ok
t/31xpc_functions.t ................................ ok
t/32xpc_variables.t ................................ ok
t/35huge_mode.t .................................... ok
t/40reader.t ....................................... ok
t/40reader_mem_error.t ............................. ok
t/41xinclude.t ..................................... ok
t/42common.t ....................................... ok
t/43options.t ...................................... ok
t/44extent.t ....................................... ok
t/45regex.t ........................................ ok
t/46err_column.t ................................... ok
t/47load_xml_callbacks.t ........................... ok
t/48_gh_pr63_detect_undef_values.t ................. ok
t/48_memleak_rt_83744.t ............................ ok
t/48_reader_undef_warning_on_empty_str_rt106830.t .. ok
t/48_removeChild_crashes_rt_80395.t ................ ok
t/48_replaceNode_DTD_nodes_rT_80521.t .............. ok
t/48_RH5_double_free_rt83779.t ..................... ok
t/48_rt123379_setNamespace.t ....................... ok
t/48_rt55000.t ..................................... ok
t/48_rt93429_recover_2_in_html_parsing.t ........... ok
t/48_SAX_Builder_rt_91433.t ........................ ok
t/48importing_nodes_IDs_rt_69520.t ................. ok
t/49_load_html.t ................................... ok
t/49callbacks_returning_undef.t .................... ok
t/49global_extent.t ................................ ok
t/50devel.t ........................................ ok
t/51_parse_html_string_rt87089.t ................... ok
t/60error_prev_chain.t ............................. ok
t/60struct_error.t ................................. ok
t/61error.t ........................................ ok
t/62overload.t ..................................... ok
t/71overloads.t .................................... ok
t/72destruction.t .................................. ok
t/80registryleak.t ................................. ok
t/90shared_clone_failed_rt_91800.t ................. skipped: optional (set THREAD_TEST=1 to run these tests)
t/90stack.t ........................................ ok
t/90threads.t ...................................... skipped: optional (set THREAD_TEST=1 to run these tests)
t/91unique_key.t ................................... ok
t/cpan-changes.t ................................... skipped: These tests are for authors only!
t/namespace-magic-scalar-rt144415.t ................ ok
t/pod-files-presence.t ............................. skipped: only for AUTHORS
t/pod.t ............................................ skipped: These tests are for authors only!
t/release-kwalitee.t ............................... skipped: These tests are for authors only!
t/style-trailing-space.t ........................... skipped: These tests are for authors only!
All tests successful.
Files=77, Tests=2547,  7 wallclock secs ( 0.61 usr  0.23 sys +  5.69 cusr  1.10 csys =  7.63 CPU)
Result: PASS

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jan 28, 2024
2.0210  2024-01-24
    - Fix copying external entity from an ext_ent_handler handler
        - shlomif/perl-XML-LibXML#81
        - thanks to Petr
    - libxml-mm: Fix function prototypes in function pointers
        - thanks to Khem Raj
clrpackages pushed a commit to clearlinux-pkgs/perl-XML-LibXML that referenced this issue Feb 7, 2024
…version 2.0210

2.0210  2024-01-24
    - Fix copying external entity from an ext_ent_handler handler
        - shlomif/perl-XML-LibXML#81
        - thanks to Petr
    - libxml-mm: Fix function prototypes in function pointers
        - thanks to Khem Raj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants