Commits

Nick Wellnhofer committed ad8f8a7

Fix segfaults when accessing attributes of DTD nodes

Check node type before accessing 'properties' struct member.

Fixes RT #71076:
https://rt.cpan.org/Ticket/Display.html?id=71076

  • Participants
  • Parent commits e722c79
  • Branches rt71076

Comments (0)

Files changed (3)

 Revision history for Perl extension XML::LibXML
 
 2.0112
+    - Fix segfaults when accessing attributes of DTD nodes
+        - https://rt.cpan.org/Ticket/Display.html?id=71076
+        - Thanks to Ralph Merridew for the report.
     - Fix https://rt.cpan.org/Ticket/Display.html?id=93429 .
         - Thanks to Nick Wellnhofer for the report and test.
 
         int wantarray = GIMME_V;
     PPCODE:
         PERL_UNUSED_VAR(ix);
-        if ( self->type != XML_ATTRIBUTE_NODE ) {
+        if ( self->type != XML_ATTRIBUTE_NODE
+             && self->type != XML_DTD_NODE ) {
             attr = self->properties;
             while ( attr != NULL ) {
                 if ( wantarray != G_SCALAR ) {
 hasAttributes( self )
         xmlNodePtr self
     CODE:
-        if ( self->type == XML_ATTRIBUTE_NODE ) {
+        if ( self->type == XML_ATTRIBUTE_NODE
+             || self->type == XML_DTD_NODE ) {
             RETVAL = 0;
         }
         else {
 use strict;
 use warnings;
 
-# Should be 38.
-use Test::More tests => 38;
+# Should be 40.
+use Test::More tests => 40;
 
 use lib './t/lib';
 use TestHelpers;
         ok( $@, ' TODO : Add test name' );
     }
 }
+
+{
+    # RT #71076: https://rt.cpan.org/Public/Bug/Display.html?id=71076
+
+    my $parser = XML::LibXML->new();
+    my $doc = $parser->parse_string(<<'EOF');
+<!DOCTYPE test [
+ <!ELEMENT test (#PCDATA)>
+ <!ATTLIST test
+  attr CDATA #IMPLIED
+ >
+]>
+<test>
+</test>
+EOF
+    my $dtd = $doc->internalSubset;
+
+    # TEST
+    ok( !$dtd->hasAttributes, 'hasAttributes' );
+    # TEST
+    is_deeply( [ $dtd->attributes ], [], 'attributes' );
+}
+