Subject: | Paring-Colon-Bug in Line 324 (Attention: Windows/Cisco-Users!) |
Date: | Tue, 19 Apr 2011 12:36:19 +0200 |
To: | bug-Net-SCP-Expect [...] rt.cpan.org |
From: | bastian.angerstein [...] deutschebahn.com |
The current code ignores the fact that the :-Charakter (Colon or
Doppelpunkt ) is a valid charakter for filenames and directorynames
(windows, linux, cisco...). Some devices like Cisco IOS and Windows-Systems
use the colon to adress mountpoints, directories or drives by default.
Problem is located in this block starting at 323 Expect.pm in Sub
"_parse_scp_string" Version 0.16:
##############################################
my $temp = join('',@parts);
@parts = split(/:/,$temp);
if (@parts) {
if (@parts > 1) {
$host = join('',@parts[0,1..scalar(@parts)-2]);
$dest = $parts[-1];
} else {
$host = $parts[0];
}
}
##############################################
The issue is related to the unlimited split operation in line 2 of this
block.
@parts = split(/:/,$temp);
To fix this issue simple limit the amount of "parts" by the third operator
'limit' of split.
See http://perldoc.perl.org/functions/split.html
In my case, and I already tested it, it would be sufficent to limit the
split to a value of 2,
@parts = split(/:/,$temp,2);
BTW: This workaround breaks the IPv6-Feature I and most people do not need,
today.
Proof of concept:
######################################################################
#!/usr/bin/perl -w
use strict;
my $temp = 'scp admin@switch-01:tmp:/blabla /tmp/blabla';
my $host = undef;
my $dest = undef;
my @parts = split(/:/,$temp,2);
if (@parts) {
if (@parts > 1) {
$host = join('',@parts[0,1..scalar(@parts)-2]);
$dest = $parts[-1];
} else {
$host = $parts[0];
}
}
print $host . "\n";
print $dest . "\n";
#########################################################################
Ouput:
#########################################################################
scp admin@switch-01
tmp:/blabla /tmp/blabla
#########################################################################
Mit freundlichen Grüßen
Bastian Angerstein
RZ- Netz (T.SVP 12)