Skip to content

Commit 2491f77

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2d90add commit 2491f77

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

cache.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,14 @@ char *strip_path_suffix(const char *path, const char *suffix);
991991
int daemon_avoid_alias(const char *path);
992992
extern int is_ntfs_dotgit(const char *name);
993993

994+
/*
995+
* Returns true iff "str" could be confused as a command-line option when
996+
* passed to a sub-program like "ssh". Note that this has nothing to do with
997+
* shell-quoting, which should be handled separately; we're assuming here that
998+
* the string makes it verbatim to the sub-program.
999+
*/
1000+
int looks_like_command_line_option(const char *str);
1001+
9941002
/**
9951003
* Return a newly allocated string with the evaluation of
9961004
* "$XDG_CONFIG_HOME/git/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise

connect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ struct child_process *git_connect(int fd[2], const char *url,
754754
return NULL;
755755
}
756756

757-
if (ssh_host[0] == '-')
757+
if (looks_like_command_line_option(ssh_host))
758758
die("strange hostname '%s' blocked", ssh_host);
759759

760760
ssh = getenv("GIT_SSH_COMMAND");

path.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,11 @@ int is_ntfs_dotgit(const char *name)
11781178
}
11791179
}
11801180

1181+
int looks_like_command_line_option(const char *str)
1182+
{
1183+
return str && str[0] == '-';
1184+
}
1185+
11811186
char *xdg_config_home(const char *filename)
11821187
{
11831188
const char *home, *config_home;

0 commit comments

Comments
 (0)