Merge branch 'tb/connect-ipv6-parse-fix' into maint
We did not parse username followed by literal IPv6 address in SSH transport URLs, e.g. ssh://user@[2001:db8::1]:22/repo.git correctly. * tb/connect-ipv6-parse-fix: t5500: show user name and host in diag-url t5601: add more test cases for IPV6 connect.c: allow ssh://user@[2001:db8::1]/repo.git
This commit is contained in:
commit
8c2ea51254
112
connect.c
112
connect.c
@ -273,28 +273,44 @@ static enum protocol get_protocol(const char *name)
|
|||||||
die("I don't handle protocol '%s'", name);
|
die("I don't handle protocol '%s'", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *host_end(char **hoststart, int removebrackets)
|
||||||
|
{
|
||||||
|
char *host = *hoststart;
|
||||||
|
char *end;
|
||||||
|
char *start = strstr(host, "@[");
|
||||||
|
if (start)
|
||||||
|
start++; /* Jump over '@' */
|
||||||
|
else
|
||||||
|
start = host;
|
||||||
|
if (start[0] == '[') {
|
||||||
|
end = strchr(start + 1, ']');
|
||||||
|
if (end) {
|
||||||
|
if (removebrackets) {
|
||||||
|
*end = 0;
|
||||||
|
memmove(start, start + 1, end - start);
|
||||||
|
end++;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
end = host;
|
||||||
|
} else
|
||||||
|
end = host;
|
||||||
|
return end;
|
||||||
|
}
|
||||||
|
|
||||||
#define STR_(s) # s
|
#define STR_(s) # s
|
||||||
#define STR(s) STR_(s)
|
#define STR(s) STR_(s)
|
||||||
|
|
||||||
static void get_host_and_port(char **host, const char **port)
|
static void get_host_and_port(char **host, const char **port)
|
||||||
{
|
{
|
||||||
char *colon, *end;
|
char *colon, *end;
|
||||||
|
end = host_end(host, 1);
|
||||||
if (*host[0] == '[') {
|
|
||||||
end = strchr(*host + 1, ']');
|
|
||||||
if (end) {
|
|
||||||
*end = 0;
|
|
||||||
end++;
|
|
||||||
(*host)++;
|
|
||||||
} else
|
|
||||||
end = *host;
|
|
||||||
} else
|
|
||||||
end = *host;
|
|
||||||
colon = strchr(end, ':');
|
colon = strchr(end, ':');
|
||||||
|
|
||||||
if (colon) {
|
if (colon) {
|
||||||
*colon = 0;
|
long portnr = strtol(colon + 1, &end, 10);
|
||||||
*port = colon + 1;
|
if (end != colon + 1 && *end == '\0' && 0 <= portnr && portnr < 65536) {
|
||||||
|
*colon = 0;
|
||||||
|
*port = colon + 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -546,13 +562,16 @@ static struct child_process *git_proxy_connect(int fd[2], char *host)
|
|||||||
return proxy;
|
return proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *get_port_numeric(const char *p)
|
static char *get_port(char *host)
|
||||||
{
|
{
|
||||||
char *end;
|
char *end;
|
||||||
|
char *p = strchr(host, ':');
|
||||||
|
|
||||||
if (p) {
|
if (p) {
|
||||||
long port = strtol(p + 1, &end, 10);
|
long port = strtol(p + 1, &end, 10);
|
||||||
if (end != p + 1 && *end == '\0' && 0 <= port && port < 65536) {
|
if (end != p + 1 && *end == '\0' && 0 <= port && port < 65536) {
|
||||||
return p;
|
*p = '\0';
|
||||||
|
return p+1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -594,14 +613,7 @@ static enum protocol parse_connect_url(const char *url_orig, char **ret_host,
|
|||||||
* Don't do destructive transforms as protocol code does
|
* Don't do destructive transforms as protocol code does
|
||||||
* '[]' unwrapping in get_host_and_port()
|
* '[]' unwrapping in get_host_and_port()
|
||||||
*/
|
*/
|
||||||
if (host[0] == '[') {
|
end = host_end(&host, 0);
|
||||||
end = strchr(host + 1, ']');
|
|
||||||
if (end) {
|
|
||||||
end++;
|
|
||||||
} else
|
|
||||||
end = host;
|
|
||||||
} else
|
|
||||||
end = host;
|
|
||||||
|
|
||||||
if (protocol == PROTO_LOCAL)
|
if (protocol == PROTO_LOCAL)
|
||||||
path = end;
|
path = end;
|
||||||
@ -662,7 +674,7 @@ struct child_process *git_connect(int fd[2], const char *url,
|
|||||||
signal(SIGCHLD, SIG_DFL);
|
signal(SIGCHLD, SIG_DFL);
|
||||||
|
|
||||||
protocol = parse_connect_url(url, &hostandport, &path);
|
protocol = parse_connect_url(url, &hostandport, &path);
|
||||||
if (flags & CONNECT_DIAG_URL) {
|
if ((flags & CONNECT_DIAG_URL) && (protocol != PROTO_SSH)) {
|
||||||
printf("Diag: url=%s\n", url ? url : "NULL");
|
printf("Diag: url=%s\n", url ? url : "NULL");
|
||||||
printf("Diag: protocol=%s\n", prot_name(protocol));
|
printf("Diag: protocol=%s\n", prot_name(protocol));
|
||||||
printf("Diag: hostandport=%s\n", hostandport ? hostandport : "NULL");
|
printf("Diag: hostandport=%s\n", hostandport ? hostandport : "NULL");
|
||||||
@ -714,28 +726,42 @@ struct child_process *git_connect(int fd[2], const char *url,
|
|||||||
char *ssh_host = hostandport;
|
char *ssh_host = hostandport;
|
||||||
const char *port = NULL;
|
const char *port = NULL;
|
||||||
get_host_and_port(&ssh_host, &port);
|
get_host_and_port(&ssh_host, &port);
|
||||||
port = get_port_numeric(port);
|
|
||||||
|
|
||||||
ssh = getenv("GIT_SSH_COMMAND");
|
if (!port)
|
||||||
if (ssh) {
|
port = get_port(ssh_host);
|
||||||
conn->use_shell = 1;
|
|
||||||
putty = 0;
|
if (flags & CONNECT_DIAG_URL) {
|
||||||
|
printf("Diag: url=%s\n", url ? url : "NULL");
|
||||||
|
printf("Diag: protocol=%s\n", prot_name(protocol));
|
||||||
|
printf("Diag: userandhost=%s\n", ssh_host ? ssh_host : "NULL");
|
||||||
|
printf("Diag: port=%s\n", port ? port : "NONE");
|
||||||
|
printf("Diag: path=%s\n", path ? path : "NULL");
|
||||||
|
|
||||||
|
free(hostandport);
|
||||||
|
free(path);
|
||||||
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
ssh = getenv("GIT_SSH");
|
ssh = getenv("GIT_SSH_COMMAND");
|
||||||
if (!ssh)
|
if (ssh) {
|
||||||
ssh = "ssh";
|
conn->use_shell = 1;
|
||||||
putty = !!strcasestr(ssh, "plink");
|
putty = 0;
|
||||||
}
|
} else {
|
||||||
|
ssh = getenv("GIT_SSH");
|
||||||
|
if (!ssh)
|
||||||
|
ssh = "ssh";
|
||||||
|
putty = !!strcasestr(ssh, "plink");
|
||||||
|
}
|
||||||
|
|
||||||
argv_array_push(&conn->args, ssh);
|
argv_array_push(&conn->args, ssh);
|
||||||
if (putty && !strcasestr(ssh, "tortoiseplink"))
|
if (putty && !strcasestr(ssh, "tortoiseplink"))
|
||||||
argv_array_push(&conn->args, "-batch");
|
argv_array_push(&conn->args, "-batch");
|
||||||
if (port) {
|
if (port) {
|
||||||
/* P is for PuTTY, p is for OpenSSH */
|
/* P is for PuTTY, p is for OpenSSH */
|
||||||
argv_array_push(&conn->args, putty ? "-P" : "-p");
|
argv_array_push(&conn->args, putty ? "-P" : "-p");
|
||||||
argv_array_push(&conn->args, port);
|
argv_array_push(&conn->args, port);
|
||||||
|
}
|
||||||
|
argv_array_push(&conn->args, ssh_host);
|
||||||
}
|
}
|
||||||
argv_array_push(&conn->args, ssh_host);
|
|
||||||
} else {
|
} else {
|
||||||
/* remove repo-local variables from the environment */
|
/* remove repo-local variables from the environment */
|
||||||
conn->env = local_repo_env;
|
conn->env = local_repo_env;
|
||||||
|
@ -541,13 +541,30 @@ check_prot_path () {
|
|||||||
test_cmp expected actual
|
test_cmp expected actual
|
||||||
}
|
}
|
||||||
|
|
||||||
check_prot_host_path () {
|
check_prot_host_port_path () {
|
||||||
cat >expected <<-EOF &&
|
local diagport
|
||||||
|
case "$2" in
|
||||||
|
*ssh*)
|
||||||
|
pp=ssh
|
||||||
|
uah=userandhost
|
||||||
|
ehost=$(echo $3 | tr -d "[]")
|
||||||
|
diagport="Diag: port=$4"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
pp=$p
|
||||||
|
uah=hostandport
|
||||||
|
ehost=$(echo $3$4 | sed -e "s/22$/:22/" -e "s/NONE//")
|
||||||
|
diagport=""
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
cat >exp <<-EOF &&
|
||||||
Diag: url=$1
|
Diag: url=$1
|
||||||
Diag: protocol=$2
|
Diag: protocol=$pp
|
||||||
Diag: hostandport=$3
|
Diag: $uah=$ehost
|
||||||
Diag: path=$4
|
$diagport
|
||||||
|
Diag: path=$5
|
||||||
EOF
|
EOF
|
||||||
|
grep -v "^$" exp >expected
|
||||||
git fetch-pack --diag-url "$1" >actual &&
|
git fetch-pack --diag-url "$1" >actual &&
|
||||||
test_cmp expected actual
|
test_cmp expected actual
|
||||||
}
|
}
|
||||||
@ -557,22 +574,20 @@ do
|
|||||||
# git or ssh with scheme
|
# git or ssh with scheme
|
||||||
for p in "ssh+git" "git+ssh" git ssh
|
for p in "ssh+git" "git+ssh" git ssh
|
||||||
do
|
do
|
||||||
for h in host host:12 [::1] [::1]:23
|
for h in host user@host user@[::1] user@::1
|
||||||
do
|
do
|
||||||
case "$p" in
|
|
||||||
*ssh*)
|
|
||||||
pp=ssh
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
pp=$p
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
test_expect_success "fetch-pack --diag-url $p://$h/$r" '
|
test_expect_success "fetch-pack --diag-url $p://$h/$r" '
|
||||||
check_prot_host_path $p://$h/$r $pp "$h" "/$r"
|
check_prot_host_port_path $p://$h/$r $p "$h" NONE "/$r"
|
||||||
'
|
'
|
||||||
# "/~" -> "~" conversion
|
# "/~" -> "~" conversion
|
||||||
test_expect_success "fetch-pack --diag-url $p://$h/~$r" '
|
test_expect_success "fetch-pack --diag-url $p://$h/~$r" '
|
||||||
check_prot_host_path $p://$h/~$r $pp "$h" "~$r"
|
check_prot_host_port_path $p://$h/~$r $p "$h" NONE "~$r"
|
||||||
|
'
|
||||||
|
done
|
||||||
|
for h in host User@host User@[::1]
|
||||||
|
do
|
||||||
|
test_expect_success "fetch-pack --diag-url $p://$h:22/$r" '
|
||||||
|
check_prot_host_port_path $p://$h:22/$r $p "$h" 22 "/$r"
|
||||||
'
|
'
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
@ -603,11 +618,11 @@ do
|
|||||||
for h in host [::1]
|
for h in host [::1]
|
||||||
do
|
do
|
||||||
test_expect_success "fetch-pack --diag-url $h:$r" '
|
test_expect_success "fetch-pack --diag-url $h:$r" '
|
||||||
check_prot_path $h:$r $p "$r"
|
check_prot_host_port_path $h:$r $p "$h" NONE "$r"
|
||||||
'
|
'
|
||||||
# Do "/~" -> "~" conversion
|
# Do "/~" -> "~" conversion
|
||||||
test_expect_success "fetch-pack --diag-url $h:/~$r" '
|
test_expect_success "fetch-pack --diag-url $h:/~$r" '
|
||||||
check_prot_host_path $h:/~$r $p "$h" "~$r"
|
check_prot_host_port_path $h:/~$r $p "$h" NONE "~$r"
|
||||||
'
|
'
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
@ -301,11 +301,17 @@ expect_ssh () {
|
|||||||
(cd "$TRASH_DIRECTORY" && rm -f ssh-expect && >ssh-output)
|
(cd "$TRASH_DIRECTORY" && rm -f ssh-expect && >ssh-output)
|
||||||
' &&
|
' &&
|
||||||
{
|
{
|
||||||
case "$1" in
|
case "$#" in
|
||||||
none)
|
1)
|
||||||
|
;;
|
||||||
|
2)
|
||||||
|
echo "ssh: $1 git-upload-pack '$2'"
|
||||||
|
;;
|
||||||
|
3)
|
||||||
|
echo "ssh: $1 $2 git-upload-pack '$3'"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "ssh: $1 git-upload-pack '$2'"
|
echo "ssh: $1 $2 git-upload-pack '$3' $4"
|
||||||
esac
|
esac
|
||||||
} >"$TRASH_DIRECTORY/ssh-expect" &&
|
} >"$TRASH_DIRECTORY/ssh-expect" &&
|
||||||
(cd "$TRASH_DIRECTORY" && test_cmp ssh-expect ssh-output)
|
(cd "$TRASH_DIRECTORY" && test_cmp ssh-expect ssh-output)
|
||||||
@ -326,7 +332,7 @@ test_expect_success !MINGW,!CYGWIN 'clone local path foo:bar' '
|
|||||||
|
|
||||||
test_expect_success 'bracketed hostnames are still ssh' '
|
test_expect_success 'bracketed hostnames are still ssh' '
|
||||||
git clone "[myhost:123]:src" ssh-bracket-clone &&
|
git clone "[myhost:123]:src" ssh-bracket-clone &&
|
||||||
expect_ssh myhost:123 src
|
expect_ssh myhost '-p 123' src
|
||||||
'
|
'
|
||||||
|
|
||||||
counter=0
|
counter=0
|
||||||
@ -336,7 +342,8 @@ counter=0
|
|||||||
test_clone_url () {
|
test_clone_url () {
|
||||||
counter=$(($counter + 1))
|
counter=$(($counter + 1))
|
||||||
test_might_fail git clone "$1" tmp$counter &&
|
test_might_fail git clone "$1" tmp$counter &&
|
||||||
expect_ssh "$2" "$3"
|
shift &&
|
||||||
|
expect_ssh "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_expect_success !MINGW 'clone c:temp is ssl' '
|
test_expect_success !MINGW 'clone c:temp is ssl' '
|
||||||
@ -359,7 +366,7 @@ done
|
|||||||
for repo in rep rep/home/project 123
|
for repo in rep rep/home/project 123
|
||||||
do
|
do
|
||||||
test_expect_success "clone [::1]:$repo" '
|
test_expect_success "clone [::1]:$repo" '
|
||||||
test_clone_url [::1]:$repo ::1 $repo
|
test_clone_url [::1]:$repo ::1 "$repo"
|
||||||
'
|
'
|
||||||
done
|
done
|
||||||
#home directory
|
#home directory
|
||||||
@ -400,24 +407,40 @@ test_expect_success 'clone ssh://host.xz:22/~repo' '
|
|||||||
'
|
'
|
||||||
|
|
||||||
#IPv6
|
#IPv6
|
||||||
test_expect_success 'clone ssh://[::1]/home/user/repo' '
|
for tuah in ::1 [::1] user@::1 user@[::1] [user@::1]
|
||||||
test_clone_url "ssh://[::1]/home/user/repo" "::1" "/home/user/repo"
|
do
|
||||||
'
|
ehost=$(echo $tuah | tr -d "[]")
|
||||||
|
test_expect_success "clone ssh://$tuah/home/user/repo" "
|
||||||
|
test_clone_url ssh://$tuah/home/user/repo $ehost /home/user/repo
|
||||||
|
"
|
||||||
|
done
|
||||||
|
|
||||||
#IPv6 from home directory
|
#IPv6 from home directory
|
||||||
test_expect_success 'clone ssh://[::1]/~repo' '
|
for tuah in ::1 [::1] user@::1 user@[::1] [user@::1]
|
||||||
test_clone_url "ssh://[::1]/~repo" "::1" "~repo"
|
do
|
||||||
'
|
euah=$(echo $tuah | tr -d "[]")
|
||||||
|
test_expect_success "clone ssh://$tuah/~repo" "
|
||||||
|
test_clone_url ssh://$tuah/~repo $euah '~repo'
|
||||||
|
"
|
||||||
|
done
|
||||||
|
|
||||||
#IPv6 with port number
|
#IPv6 with port number
|
||||||
test_expect_success 'clone ssh://[::1]:22/home/user/repo' '
|
for tuah in [::1] user@[::1] [user@::1]
|
||||||
test_clone_url "ssh://[::1]:22/home/user/repo" "-p 22 ::1" "/home/user/repo"
|
do
|
||||||
'
|
euah=$(echo $tuah | tr -d "[]")
|
||||||
|
test_expect_success "clone ssh://$tuah:22/home/user/repo" "
|
||||||
|
test_clone_url ssh://$tuah:22/home/user/repo '-p 22' $euah /home/user/repo
|
||||||
|
"
|
||||||
|
done
|
||||||
|
|
||||||
#IPv6 from home directory with port number
|
#IPv6 from home directory with port number
|
||||||
test_expect_success 'clone ssh://[::1]:22/~repo' '
|
for tuah in [::1] user@[::1] [user@::1]
|
||||||
test_clone_url "ssh://[::1]:22/~repo" "-p 22 ::1" "~repo"
|
do
|
||||||
'
|
euah=$(echo $tuah | tr -d "[]")
|
||||||
|
test_expect_success "clone ssh://$tuah:22/~repo" "
|
||||||
|
test_clone_url ssh://$tuah:22/~repo '-p 22' $euah '~repo'
|
||||||
|
"
|
||||||
|
done
|
||||||
|
|
||||||
test_expect_success 'clone from a repository with two identical branches' '
|
test_expect_success 'clone from a repository with two identical branches' '
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user