Skip Menu |

This queue is for tickets about the File-Scan-ClamAV CPAN distribution.

Report information
The Basics
Id: 6970
Status: resolved
Worked: 30 min
Priority: 0/
Queue: File-Scan-ClamAV

People
Owner: CFABER [...] cpan.org
Requestors: piper [...] dev-null.net
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.06
Fixed in: (no value)



Subject: Possible bug in scan return
I'm having a problem with the scan routine in File::Scan::ClamAV 1.06 when there is no virus detected. sub _scan_shallow returns undef to scan when there is no virus. The problem comes in when you try to return the first and second values from an non-existant arrayref. Would it not be better to test the array and return undef on an empty array like so? [code] sub scan { my $self = shift; $self->_seterrstr; my @results; if($self->{find_all}){ @results = $self->_scan('SCAN', @_); } else { @results = $self->_scan_shallow('SCAN', @_); return unless @results; # return undef if @results is empty return ($_->[0], $_->[1]); } my %f; for(@results){ $f{ $_->[0] } = $_->[1]; } return %f; } [/code] Here is the test code I used: [code] #!/usr/bin/perl use warnings; use strict; use File::Scan::ClamAV; use Data::Dumper; my $av = File::Scan::ClamAV->new(); if($av->ping) { my %found = $av->scan('/path/to/file'); print Dumper(\%found); } [/code] Which produces: [results] Use of uninitialized value in list assignment at ./test.pl line 9. $VAR1 = { '' => undef }; [/results] With the line I added I get this: [results] $VAR1 = {}; [/results] [system info] perl -v This is perl, v5.8.1 built for i686-linux uname - a Linux 2.4.26-tfadmin #2 SMP Sun May 30 23:48:09 IST 2004 i686 i686 i386 GNU/Linux [/system info] Regards, Charlie
Hi, The problem described is really behavior that shouldn't be taking place. At least it's not documented behavior. The solution is to not return anything after the shallow scan. I'm not sure why this extra return managed to make it's way in here in the first place, Oh well. I've corrected the problem and uploaded a new build of the module (version 1.8) to CPAN. Thanks for the heads up. [guest - Thu Jul 15 02:18:23 2004]: Show quoted text
> I'm having a problem with the scan routine in File::Scan::ClamAV 1.06 > when there is no virus detected. sub _scan_shallow returns undef > to scan when there is no virus. The problem comes in when you try > to return the first and second values from an non-existant > arrayref. Would it not be better to test the array and return > undef on an empty array like so? > > [code] > sub scan { > my $self = shift; > $self->_seterrstr; > my @results; > > if($self->{find_all}){ > @results = $self->_scan('SCAN', @_); > } else { > @results = $self->_scan_shallow('SCAN', @_); > return unless @results; # return undef if @results is empty > return ($_->[0], $_->[1]); > } > > my %f; > for(@results){ > $f{ $_->[0] } = $_->[1]; > } > > return %f; > > } > [/code] > > > Here is the test code I used: > > [code] > #!/usr/bin/perl > use warnings; > use strict; > use File::Scan::ClamAV; > use Data::Dumper; > > my $av = File::Scan::ClamAV->new(); > if($av->ping) { > my %found = $av->scan('/path/to/file'); > print Dumper(\%found); > } > [/code] > > Which produces: > > [results] > Use of uninitialized value in list assignment at ./test.pl line 9. > $VAR1 = { > '' => undef > }; > [/results] > > With the line I added I get this: > > [results] > $VAR1 = {}; > [/results] > > [system info] > perl -v > This is perl, v5.8.1 built for i686-linux > uname - a > Linux 2.4.26-tfadmin #2 SMP Sun May 30 23:48:09 IST 2004 i686 i686 > i386 GNU/Linux > [/system info] > > Regards, > Charlie
This bug identified a misbehavior in the scan() application. It shouldn't have returned an array at all. It's since been fixed in the 1.8 version.