Commits

Anonymous committed e1b973f

Log: Initialization problem fixed in parse_xml_chunk().

Modified Files:
Makefile.PL
o fixed a comment

LibXML.xs
[FIX] parse_xml_chunk() now initializes the fragment code correctly
no segmentation faults and errors while moving data from one
fragment to another.

The fix is to initialize the entire node list while appending
it to the document fragment parse_xml_chunk() returns.

Changes
+ note about the fix

t/02parse.t
+ tests to test the problem

Comments (0)

Files changed (4)

 Revision history for Perl extension XML::LibXML
 
 1.58
+   - fixed a pointer initialization in parse_xml_chunk(), fixes 
+     random several segmentation faults on document fragments.
    - added NSCLEAN feature to the parser interface (bug 4560)
    - minor code cleanups
    - updated libxml2 blacklist.
                 fragment->children = rv;
                 rv->parent = fragment;
                 rv_end = rv;
-                while ( rv_end != NULL ) {
-                    fragment->last = rv_end;
+                while ( rv_end->next != NULL ) {
                     rv_end->parent = fragment;
                     rv_end = rv_end->next;
                 }
+                /* the following line is important, otherwise we'll have 
+                   occasional segmentation faults
+                 */
+                rv_end->parent = fragment;
+                fragment->last = rv_end;
             }
 
             /* free the chunk we created */
 }
 
 if ($config{LIBS} !~ /\-lm\b/) {
-    # math support is important, but is not available separate in W32
+    # math support is important, but is not available separately in W32
     $config{LIBS} .= $is_Win32 ? '' :' -lm';
 }
 # -------------------------------------------------------------------------- #
 
 BEGIN { use XML::LibXML;
     if ( XML::LibXML::LIBXML_VERSION >= 20600 ) {
-        plan tests => 468; 
+        plan tests => 472; 
     }
     else {
-        plan tests => 460;
+        plan tests => 464;
         print "# skip NS cleaning tests\n";
     }
 };
         ok($@);
     }
 
+    {
+        print "# 5.1.1 Segmenation fault tests\n";
+
+        my $sDoc   = '<C/><D/>';
+        my $sChunk = '<A/><B/>';
+
+        my $parser = XML::LibXML->new();
+        my $doc = $parser->parse_xml_chunk( $sDoc,  undef );
+        my $chk = $parser->parse_xml_chunk( $sChunk,undef );
+
+        my $fc = $doc->firstChild;
+
+        $doc->appendChild( $chk );
+
+        ok( $doc->toString(), '<C/><D/><A/><B/>' );
+    }
+
+    {
+        print "# 5.1.2 Segmenation fault tests\n";
+
+        my $sDoc   = '<C/><D/>';
+        my $sChunk = '<A/><B/>';
+
+        my $parser = XML::LibXML->new();
+        my $doc = $parser->parse_xml_chunk( $sDoc,  undef );
+        my $chk = $parser->parse_xml_chunk( $sChunk,undef );
+
+        my $fc = $doc->firstChild;
+
+        $doc->insertAfter( $chk, $fc );
+
+        ok( $doc->toString(), '<C/><A/><B/><D/>' );
+    }
+
+    {
+        print "# 5.1.3 Segmenation fault tests\n";
+
+        my $sDoc   = '<C/><D/>';
+        my $sChunk = '<A/><B/>';
+
+        my $parser = XML::LibXML->new();
+        my $doc = $parser->parse_xml_chunk( $sDoc,  undef );
+        my $chk = $parser->parse_xml_chunk( $sChunk,undef );
+
+        my $fc = $doc->firstChild;
+
+        $doc->insertBefore( $chk, $fc );
+
+        ok( $doc->toString(), '<A/><B/><C/><D/>' );
+    }
+
+    ok(1);
+
     print "# 5.2 SAX CHUNK PARSER\n";
 
     my $handler = XML::LibXML::SAX::Builder->new();
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.