Commits

Shlomi Fish committed 7928a60

Fix a double free in XML::LibXML::Reader.

Comments (0)

Files changed (3)

 Revision history for Perl extension XML::LibXML
 
+2.0013          Tue  4 Dec 17:40:27 IST 2012
+    - Fix a memory error (double-free) in XML::LibXML::Reader if we reached
+    EOF and
+    then called destroy.
+        - discovered by Shlomi Fish.
+        - Fixed by Shlomi Fish.
+        - see t/40reader_mem_error.t
+
 2.0012          Fri  9 Nov 06:39:32 IST 2012
     - Fix support for references to scalars with overloaded stringification
     magic.
 	/* SV * error_sv = NULL;
            xmlTextReaderErrorFunc f = NULL; */
     CODE:
-	doc = xmlTextReaderCurrentDoc(reader);
+
+    if (xmlTextReaderReadState(reader) != XML_TEXTREADER_MODE_EOF) {
+        doc = xmlTextReaderCurrentDoc(reader);
         if (doc) {
-          perl_doc = PmmNodeToSv((xmlNodePtr)doc, NULL);
-          if ( PmmREFCNT(SvPROXYNODE(perl_doc))>1 ) {
-	    /* was incremented in document() to prevent from PMM destruction */
-	    PmmREFCNT_dec(SvPROXYNODE(perl_doc));
-	  }
-          SvREFCNT_dec(perl_doc);
-	}
+            perl_doc = PmmNodeToSv((xmlNodePtr)doc, NULL);
+            if ( PmmREFCNT(SvPROXYNODE(perl_doc))>1 ) {
+                /* was incremented in document() to prevent from PMM destruction */
+                PmmREFCNT_dec(SvPROXYNODE(perl_doc));
+            }
+            SvREFCNT_dec(perl_doc);
+        }
+    }
         if (xmlTextReaderReadState(reader) != XML_TEXTREADER_MODE_CLOSED) {
 	  xmlTextReaderClose(reader);
 	}
 t/31xpc_functions.t
 t/32xpc_variables.t
 t/40reader.t
+t/40reader_mem_error.t
 t/41xinclude.t
 t/42common.t
 t/43options.t
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.