connect.c: Corner case for IPv6
PATCH v6 7/10 connect.c: Corner case for IPv6
Commit faea9ccbadf75128 introduced "user-relative paths":
"ssh://host.xz/~junio/repo" is the same as "host.xz:~junio/repo".
Commit 356bece0a27258181 "Support [address] in URLs" introduced a regression:
When an URL like "[::1]:/~repo" is used, the replacement of "/~" with "~" was enabled for IPv6 host names, and "[::1]:/~repo" is converted into "[::1]:~repo".
Solution:
Don't use "if (url != hostname)", but look at the separator instead. Rename the variable "c" into separator.
--- connect.c | 14 +++++++------- t/t5500-fetch-pack.sh | 16 ++++------------ t/t5601-clone.sh | 12 ++---------- 3 files changed, 13 insertions(+), 29 deletions(-)
connect.c +7 -7
@@ -566,7 +566,7 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_host,char *url;char *host, *path;char *end; -int c; +int separator;enum protocol protocol =PROTO_LOCAL ;int free_path =0 ;char *port =NULL ;
@@ -581,10 +581,10 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_host, *host ='\0' ; protocol =get_protocol (url); host +=3 ; - c ='/' ; + separator ='/' ; }else { host = url; - c =':' ; + separator =':' ; }/*
@@ -604,9 +604,9 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_host, }else end = host; - path =strchr (end, c); + path =strchr (end, separator);if (path && !has_dos_drive_prefix (end)) { -if (c ==':' ) { +if (separator ==':' ) {if (host != url || path <strchrnul (host,'/' )) { protocol =PROTO_SSH ; *path++ ='\0' ;
@@ -623,7 +623,7 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_host,* null-terminate hostname and point path to ~ for URL's like this: * ssh://host.xz/~user/repo */ -if (protocol !=PROTO_LOCAL && host != url) { +if (protocol !=PROTO_LOCAL && separator =='/' ) {char *ptr = path;if (path[1 ] =='~' ) path++;
@@ -638,7 +638,7 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_host,/* * Add support for ssh port: ssh://host.xy:<port>/... */ -if (protocol ==PROTO_SSH && host != url) +if (protocol ==PROTO_SSH && separator =='/' ) port =get_port (end); *ret_host =xstrdup (host);
t/t5500-fetch-pack.sh +4 -12
@@ -604,19 +604,11 @@ do test_expect_success "fetch-pack --diag-url $h:$r" ' check_prot_path $h:$r $p "$r" ' + # No "/~" -> "~" conversion + test_expect_success "fetch-pack --diag-url $h:/~$r" ' + check_prot_host_path $h:/~$r $p "$hh" "/~$r" + ' done - h=host - hh=host - # "/~" -> "~" conversion - test_expect_failure "fetch-pack --diag-url $h:/~$r" ' - check_prot_host_path $h:/~$r $p "$hh" "~$r" - ' - h=[::1] - hh=$(echo $h | tr -d "[]") - # "/~" -> "~" conversion - test_expect_success "fetch-pack --diag-url $h:/~$r" ' - check_prot_host_path $h:/~$r $p "$hh" "~$r" - ' done test_expect_success MINGW 'fetch-pack --diag-url file://c:/repo' '
t/t5601-clone.sh +2 -10
@@ -356,15 +356,7 @@ do done #ipv6 -# failing -for repo in /~proj -do - test_expect_failure "clone [::1]:$repo" ' - test_clone_url [::1]:$repo ::1 $repo - ' -done - -for repo in rep rep/home/project 123 +for repo in rep rep/home/project 123 /~proj do test_expect_success "clone [::1]:$repo" ' test_clone_url [::1]:$repo ::1 $repo
@@ -373,7 +365,7 @@ done # Corner cases # failing -for repo in [foo]bar/baz:qux [foo/bar]:baz +for url in [foo]bar/baz:qux [foo/bar]:baz do test_expect_failure "clone $url is not ssh" ' test_clone_url $url none
Signature · 1 line
1.8.4.457.g424cb08
Quoted 8 lines · Torsten Bögershausen
Commit
faea9ccbadf75128introduced "user-relative paths":
"ssh://host.xz/~junio/repo" is the same as "host.xz:~junio/repo".Commit
356bece0a27258181"Support [address] in URLs" introduced a regression:
When an URL like "[::1]:/~repo" is used, the replacement of "/~" with "~" was enabled for IPv6 host names, and "[::1]:/~repo" is converted into "[::1]:~repo".
Quoted 4 lines
Solution:
Don't use "if (url != hostname)", but look at the separator instead. Rename the variable "c" into separator.
---
Sign-off?
The above explanation sounds sensible.
Thanks.
Quoted 119 lines
connect.c | 14 +++++++------- t/t5500-fetch-pack.sh | 16 ++++------------ t/t5601-clone.sh | 12 ++---------- 3 files changed, 13 insertions(+), 29 deletions(-)connect.c +7
-7@@ -566,7 +566,7 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_host,char *url;char *host, *path;char *end; -int c; +int separator;enum protocol protocol =PROTO_LOCAL ;int free_path =0 ;char *port =NULL ;@@ -581,10 +581,10 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_host, *host ='\0' ; protocol =get_protocol (url); host +=3 ; - c ='/' ; + separator ='/' ; }else { host = url; - c =':' ; + separator =':' ; }/* @@ -604,9 +604,9 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_host, }else end = host; - path =strchr (end, c); + path =strchr (end, separator);if (path && !has_dos_drive_prefix (end)) { -if (c ==':' ) { +if (separator ==':' ) {if (host != url || path <strchrnul (host,'/' )) { protocol =PROTO_SSH ; *path++ ='\0' ;@@ -623,7 +623,7 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_host,* null-terminate hostname and point path to ~ for URL's like this: * ssh://host.xz/~user/repo */ -if (protocol !=PROTO_LOCAL && host != url) { +if (protocol !=PROTO_LOCAL && separator =='/' ) {char *ptr = path;if (path[1 ] =='~' ) path++;@@ -638,7 +638,7 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_host,/* * Add support for ssh port: ssh://host.xy:<port>/... */ -if (protocol ==PROTO_SSH && host != url) +if (protocol ==PROTO_SSH && separator =='/' ) port =get_port (end); *ret_host =xstrdup (host);t/t5500-fetch-pack.sh +4
-12@@ -604,19 +604,11 @@ do test_expect_success "fetch-pack --diag-url $h:$r" ' check_prot_path $h:$r $p "$r" ' + # No "/~" -> "~" conversion + test_expect_success "fetch-pack --diag-url $h:/~$r" ' + check_prot_host_path $h:/~$r $p "$hh" "/~$r" + ' done - h=host - hh=host - # "/~" -> "~" conversion - test_expect_failure "fetch-pack --diag-url $h:/~$r" ' - check_prot_host_path $h:/~$r $p "$hh" "~$r" - ' - h=[::1] - hh=$(echo $h | tr -d "[]") - # "/~" -> "~" conversion - test_expect_success "fetch-pack --diag-url $h:/~$r" ' - check_prot_host_path $h:/~$r $p "$hh" "~$r" - ' done test_expect_success MINGW 'fetch-pack --diag-url file://c:/repo' 't/t5601-clone.sh +2
-10@@ -356,15 +356,7 @@ do done #ipv6 -# failing -for repo in /~proj -do - test_expect_failure "clone [::1]:$repo" ' - test_clone_url [::1]:$repo ::1 $repo - ' -done - -for repo in rep rep/home/project 123 +for repo in rep rep/home/project 123 /~proj do test_expect_success "clone [::1]:$repo" ' test_clone_url [::1]:$repo ::1 $repo@@ -373,7 +365,7 @@ done # Corner cases # failing -for repo in [foo]bar/baz:qux [foo/bar]:baz +for url in [foo]bar/baz:qux [foo/bar]:baz do test_expect_failure "clone $url is not ssh" ' test_clone_url $url none