Commit 2491f77b authored by Jeff King's avatar Jeff King Committed by Junio C Hamano

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: default avatarJeff King <peff@peff.net>
Reviewed-by: default avatarJonathan Nieder <jrnieder@gmail.com>
Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
parent 2d90add5
......@@ -991,6 +991,14 @@ char *strip_path_suffix(const char *path, const char *suffix);
int daemon_avoid_alias(const char *path);
extern int is_ntfs_dotgit(const char *name);
/*
* Returns true iff "str" could be confused as a command-line option when
* passed to a sub-program like "ssh". Note that this has nothing to do with
* shell-quoting, which should be handled separately; we're assuming here that
* the string makes it verbatim to the sub-program.
*/
int looks_like_command_line_option(const char *str);
/**
* Return a newly allocated string with the evaluation of
* "$XDG_CONFIG_HOME/git/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise
......
......@@ -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");
......
......@@ -1178,6 +1178,11 @@ int is_ntfs_dotgit(const char *name)
}
}
int looks_like_command_line_option(const char *str)
{
return str && str[0] == '-';
}
char *xdg_config_home(const char *filename)
{
const char *home, *config_home;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment