LP#1667835: avoid edi_fetcher.pl crash upon fetching zero-length file
authorGalen Charlton <gmc@equinoxinitiative.org>
Fri, 24 Feb 2017 23:04:29 +0000 (18:04 -0500)
committerJason Stephenson <jason@sigio.com>
Fri, 3 Mar 2017 17:42:46 +0000 (12:42 -0500)
This patch fixes an issue that could cause edi_fetcher.pl to crash
if the EDI partner supplies a zero-length file for Net::FTP to
download; such files are now skipped.

Testing would entail setting up an FTP server that contains a
zero-length file, then setting up an EDI remote account and
using edi_fetcher.pl to try to retrieve the file.

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Chris Sharp <csharp@georgialibraries.org>
Signed-off-by: Jason Stephenson <jason@sigio.com>
Open-ILS/src/perlmods/lib/OpenILS/Utils/RemoteAccount.pm

index 8c7682d..b4a8f1e 100644 (file)
@@ -605,6 +605,7 @@ sub get_ftp {
     my $self = shift;
     my $filename;
 
+    my $remote_filename = $self->{get_args}->[0];
     eval { $filename = $self->_ftp->get(@{$self->{get_args}}) };
     if ($@ or not $filename) {
         $logger->error(
@@ -614,6 +615,16 @@ sub get_ftp {
         );
         return;
     }
+    if (!defined(${$filename->sref})) {
+        # the underlying scalar is still undef, so Net::FTP must have
+        # successfully retrieved an empty file... which we should skip
+        $logger->error(
+            $self->_error(
+                "get $remote_filename from", $self->remote_host, ": remote file is zero-length"
+            )
+        );
+        return;
+    }
 
     $self->local_file($filename);
     $logger->info(