Bug 1847

Summary: SFTP doen't work well with IPV6 address
Product: Portable OpenSSH Reporter: Adam <adamchen>
Component: sftpAssignee: Assigned to nobody <unassigned-bugs>
Status: CLOSED FIXED    
Severity: normal CC: djm
Priority: P2    
Version: 5.6p1   
Hardware: All   
OS: Linux   
Bug Depends on:    
Bug Blocks: 1845    

Description Adam 2010-12-22 15:51:30 AEDT
Greetings.

I'm using ssh 5.6p1 release and have met a problem using SFTP with IPV6 address.  Here's a brief.

When I ran command "sftp -6 fe80::217:8ff:fe7c:d91c", SFTP threw out below error messages.

ssh: Could not resolve hostname fe80: host nor service provided, or not known
Connection closed


See that the hostname has been cut as "fe80", and of cource this could not be resolved.  By reading sftp.c, I noticed that this happened in line 2207.

2207         if ((cp = colon(host)) != NULL) {
2208             *cp++ = '\0';
2209             file1 = cp;
2210         }

The function colon(…) is used to analyze if user's input command is like “sftp host_address:/directory”.  If it is, colon(…) modifies the value of “host” from “host_address:/directory” to “host_address”, and returns value “/directory” to string “cp”.

In current case, I think colon(...) incorrectly cuts a valid IPV6 address.  
Would you please verify this bug and do a fix?  Thanks.
Comment 1 Adam 2010-12-22 16:52:13 AEDT
Since sftp allows users to use enter command like "sftp address:/directory", there could also be some problems when address is an IPV6 address.
Comment 2 Damien Miller 2011-05-06 11:09:27 AEST
You should enclose IPv6 addresses in square brackets to avoid ambiguity. E.g. sftp [::1]

I'll add a note to sftp.1:

+.Pp
+Since some usage formats use colon characters to delimit host names from path
+names, IPv6 addresses must be enclosed in square brackets to avoid ambiguity.
+.Pp
Comment 3 Damien Miller 2011-09-06 15:33:07 AEST
close resolved bugs now that openssh-5.9 has been released