Commits

Shlomi Fish committed 5088fff

Gracefully handle returned undef()s in the read callback under -w ($^W):
- t/49callbacks_returning_undef.t
- https://rt.cpan.org/Ticket/Display.html?id=70321

Comments (0)

Files changed (4)

 Revision history for Perl extension XML::LibXML
 
+    - Gracefully handle returned undef()s in the read callback under -w ($^W):
+        - t/49callbacks_returning_undef.t
+        - https://rt.cpan.org/Ticket/Display.html?id=70321
+
 1.84            Sat Jul 23 23:12:28 IDT 2011
     - Fix for perl 5.8.x before 5.8.8:
         - "You can now use the x operator to repeat a qw// list. This used to raise a syntax error."
     STRLEN res_len;
     const char * output;
     SV * ctxt;
+    SV * output_sv;
 
     res_len = 0;
     ctxt = (SV *)context;
             croak_obj;
         }
 
-        output = POPp;
+        /*
+         * Handle undef()s gracefully, to avoid using POPpx which warns upon $^W
+         * being set. See t/49callbacks_returning_undef.t and:
+         * https://rt.cpan.org/Ticket/Display.html?id=70321
+         * */
+        
+        output_sv = POPs;
+        output = SvOK(output_sv) ? SvPVx_nolen(output_sv) : NULL;    
+
         if (output != NULL) {
             res_len = strlen(output);
             if (res_len) {
 t/48_rt55000.t
 t/48importing_nodes_IDs_rt_69520.t
 t/49_load_html.t
+t/49callbacks_returning_undef.t
 t/49global_extent.t
 t/60error_prev_chain.t
 t/60struct_error.t

t/49callbacks_returning_undef.t

+
+# This is a bug fix for:
+# https://rt.cpan.org/Ticket/Display.html?id=70321
+#
+# When the match callback returns 1 and the open callback returns undef, then the
+# read callback (inside the XS code) warnings about:
+# "Use of uninitialized value in subroutine entry at".
+#
+# This is due to the value returned being undef and processed by SvPV.
+
+use strict;
+use warnings;
+
+use lib './t/lib';
+
+use Test::More tests => 1;
+
+use XML::LibXML;
+
+my $string = <<EOF;
+<?xml version="1.0" encoding="us-ascii"?>
+<!DOCTYPE foo [
+    <!ENTITY foo SYSTEM "file:///etc/passwd">
+]>
+<methodCall>
+  <methodName>metaWeblog.newPost</methodName>
+  <params>
+    <param>
+      <value><string>Entity test: &foo;</string></value>
+    </param>
+  </params>
+</methodCall>
+EOF
+
+my $icb    = XML::LibXML::InputCallback->new();
+
+my $match_ret = 1;
+$icb->register_callbacks( [ 
+        sub { my $to_ret = $match_ret; $match_ret = 0; return $to_ret; }, 
+        sub { return undef; },
+        undef,
+        undef 
+    ] 
+);
+
+my $parser = XML::LibXML->new();
+$parser->input_callbacks($icb);
+my $num_warnings = 0;
+{
+    local $^W = 1;
+    local $SIG{__WARN__} = sub {
+        $num_warnings++;
+    };
+    my $doc = $parser->parse_string($string);
+}
+# TEST
+is ($num_warnings, 0, "No warnings were recorded.");
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.