Subject: | getFullFilenameBREAKCHROOT does not return filename |
Date: | Wed, 30 May 2018 06:59:08 +0000 |
To: | "bug-Net-SFTP-SftpServer [...] rt.cpan.org" <bug-Net-SFTP-SftpServer [...] rt.cpan.org> |
From: | Michael Harris <michael.harris [...] ericsson.com> |
Hello,
I've found that the function Net::SFTP::SftpServer::File::getFullFilenameBREAKCHROOT does not return the filename portion, only the chroot dir.
I get this warning as well:
Use of uninitialized value in concatenation (.) or string at /home/itk/perl5/lib/perl5//Net/SFTP/SftpServer.pm line 2238.
Looking into it further, I can see the problem:
my $ident = scalar $self;
'scalar' only asks perl to treat the expression as a scalar rather than a list, so $ident ends up holding another reference to the same object.
bless $self, 'Net::SFTP::SftpServer::FileChrootBroken';
return $chroot_dir . $filename_of{$ident}
Re-blessing $self also reblesses $ident, since they point to the same object. Therefore, $filename_of{$ident} no longer refers to the same entry in %filename_of.
I suspect you intended $ident to contain a stringified version of $self, so you could use it as a hash key. This would work better:
my $ident = "$self";
There is another problem with the re-blessing - it means that DESTROY is never run for the objects. The various hashes you have there will have entries left over from every file. It's even possible that a subsequent file object will be created with the same heap address, and therefore end up with the same "ident" as a previous instance, and maybe have various left over bits of state associated with them.
Regards
Mike Harris