connect: factor out "looks like command line option" check

We reject hostnames that start with a dash because they may
be confused for command-line options. Let's factor out that
notion into a helper function, as we'll use it in more
places. And while it's simple now, it's not clear if some
systems might need more complex logic to handle all cases.

Signed-off-by: Jeff King <peff@peff.net>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King
2017-07-28 15:25:45 -04:00
committed by Junio C Hamano
parent 2d90add5ad
commit 2491f77b90
3 changed files with 14 additions and 1 deletions

View File

@ -754,7 +754,7 @@ struct child_process *git_connect(int fd[2], const char *url,
return NULL;
}
if (ssh_host[0] == '-')
if (looks_like_command_line_option(ssh_host))
die("strange hostname '%s' blocked", ssh_host);
ssh = getenv("GIT_SSH_COMMAND");