You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by mm...@apache.org on 2008/10/01 02:43:36 UTC

svn commit: r700648 - in /spamassassin/trunk/lib/Mail/SpamAssassin/Plugin: DCC.pm Pyzor.pm

Author: mmartinec
Date: Tue Sep 30 17:43:36 2008
New Revision: 700648

URL: http://svn.apache.org/viewvc?rev=700648&view=rev
Log:
Pyzor and DCC: replace line-by-line reading from a pipe with a read() to avoid Perl i/o bug on some platforms, just in case

Modified:
    spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/DCC.pm
    spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Pyzor.pm

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/DCC.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/DCC.pm?rev=700648&r1=700647&r2=700648&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/DCC.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/DCC.pm Tue Sep 30 17:43:36 2008
@@ -616,8 +616,11 @@
              $tmpf, 1, $path, "-H", "-x", "0", @opts);
     $pid or die "$!\n";
 
-    $! = 0; my @null = <DCC>;
-    $!==0  or die "error reading from pipe: $!";
+    # read+split avoids a Perl I/O bug (Bug 5985)
+    my($inbuf,$nread,$resp); $resp = '';
+    while ( $nread=read(DCC,$inbuf,8192) ) { $resp .= $inbuf }
+    defined $nread  or die "error reading from pipe: $!";
+    my @null = split(/^/m, $resp, -1);  undef $resp;
 
     my $errno = 0;  close DCC or $errno = $!;
     proc_status_ok($?,$errno)
@@ -812,9 +815,13 @@
     my $pid = Mail::SpamAssassin::Util::helper_app_pipe_open(*DCC,
                 $tmpf, 1, $path, "-H", "-t", "many", "-x", "0", @opts);
     $pid or die "$!\n";
-    $! = 0; my @ignored = <DCC>;
-    $!==0  or die "error reading from pipe: $!";
-    dbg("dcc: empty response")  if !@ignored;
+
+    my($inbuf,$nread,$nread_all); $nread_all = 0;
+    # response is ignored, just check its existence
+    while ( $nread=read(DCC,$inbuf,8192) ) { $nread_all += $nread }
+    defined $nread  or die "error reading from pipe: $!";
+
+    dbg("dcc: empty response")  if $nread_all < 1;
 
     my $errno = 0;  close DCC or $errno = $!;
     # closing a pipe also waits for the process executing on the pipe to

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Pyzor.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Pyzor.pm?rev=700648&r1=700647&r2=700648&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Pyzor.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Pyzor.pm Tue Sep 30 17:43:36 2008
@@ -279,8 +279,11 @@
 	$tmpf, 1, $path, split(' ', $opts), "check");
     $pid or die "$!\n";
 
-    $! = 0; @response = <PYZOR>;
-    $!==0  or die "error reading from pipe: $!";
+    # read+split avoids a Perl I/O bug (Bug 5985)
+    my($inbuf,$nread,$resp); $resp = '';
+    while ( $nread=read(PYZOR,$inbuf,8192) ) { $resp .= $inbuf }
+    defined $nread  or die "error reading from pipe: $!";
+    @response = split(/^/m, $resp, -1);  undef $resp;
 
     my $errno = 0;  close PYZOR or $errno = $!;
     if (proc_status_ok($?,$errno)) {
@@ -405,9 +408,12 @@
 	$tmpf, 1, $path, split(' ', $opts), "report");
     $pid or die "$!\n";
 
-    $! = 0; my @ignored = <PYZOR>;
-    $!==0  or die "error reading from pipe: $!";
-    dbg("pyzor: empty response")  if !@ignored;
+    my($inbuf,$nread,$nread_all); $nread_all = 0;
+    # response is ignored, just check its existence
+    while ( $nread=read(PYZOR,$inbuf,8192) ) { $nread_all += $nread }
+    defined $nread  or die "error reading from pipe: $!";
+
+    dbg("pyzor: empty response")  if $nread_all < 1;
 
     my $errno = 0;  close PYZOR or $errno = $!;
     # closing a pipe also waits for the process executing on the pipe to