]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Don Heap spotted that our heuristics for dealing with IPv6 literal addresses
authorJacob Nevins <jacobn@chiark.greenend.org.uk>
Sat, 11 Feb 2006 19:10:01 +0000 (19:10 +0000)
committerJacob Nevins <jacobn@chiark.greenend.org.uk>
Sat, 11 Feb 2006 19:10:01 +0000 (19:10 +0000)
in the PSCP command line were bogus, giving "remote to remote not supported"
errors with filenames like '[].txt'. Made the heuristic less bogus.

[originally from svn r6551]

pscp.c

diff --git a/pscp.c b/pscp.c
index 575025f21a7471b05d7f378d2b297914f99ad054..b67782eb29208acbbfc0bb8f40a2c2b58ef6d6a0 100644 (file)
--- a/pscp.c
+++ b/pscp.c
@@ -546,26 +546,23 @@ static void print_stats(char *name, unsigned long size, unsigned long done,
  */
 static char *colon(char *str)
 {
-    /* Check and process IPv6 literal addresses
-     * (eg: 'jeroen@[2001:db8::1]:myfile.txt') */
-    char *ipv6 = strchr(str, '[');
-    if (ipv6) {
-       str = strchr(str, ']');
-       if (str) {
-           /* Terminate on the closing bracket */
-           *str++ = '\0';
-           return (str);
-       }
-       return (NULL);
-    }
-
     /* We ignore a leading colon, since the hostname cannot be
        empty. We also ignore a colon as second character because
        of filenames like f:myfile.txt. */
-    if (str[0] == '\0' || str[0] == ':' || str[1] == ':')
+    if (str[0] == '\0' || str[0] == ':' ||
+        (str[0] != '[' && str[1] == ':'))
        return (NULL);
-    while (*str != '\0' && *str != ':' && *str != '/' && *str != '\\')
+    while (*str != '\0' && *str != ':' && *str != '/' && *str != '\\') {
+       if (*str == '[') {
+           /* Skip over IPv6 literal addresses
+            * (eg: 'jeroen@[2001:db8::1]:myfile.txt') */
+           char *ipv6_end = strchr(str, ']');
+           if (ipv6_end) {
+               str = ipv6_end;
+           }
+       }
        str++;
+    }
     if (*str == ':')
        return (str);
     else