Skip to content

Commit bb61c17

Browse files
peffdscho
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]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 3d95081 commit bb61c17

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
@@ -1113,6 +1113,14 @@ char *strip_path_suffix(const char *path, const char *suffix);
11131113
int daemon_avoid_alias(const char *path);
11141114
extern int is_ntfs_dotgit(const char *name);
11151115

1116+
/*
1117+
* Returns true iff "str" could be confused as a command-line option when
1118+
* passed to a sub-program like "ssh". Note that this has nothing to do with
1119+
* shell-quoting, which should be handled separately; we're assuming here that
1120+
* the string makes it verbatim to the sub-program.
1121+
*/
1122+
int looks_like_command_line_option(const char *str);
1123+
11161124
/**
11171125
* Return a newly allocated string with the evaluation of
11181126
* "$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
@@ -835,7 +835,7 @@ struct child_process *git_connect(int fd[2], const char *url,
835835
return NULL;
836836
}
837837

838-
if (ssh_host[0] == '-')
838+
if (looks_like_command_line_option(ssh_host))
839839
die("strange hostname '%s' blocked", ssh_host);
840840

841841
ssh = get_ssh_command();

path.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,11 @@ int is_ntfs_dotgit(const char *name)
12621262
}
12631263
}
12641264

1265+
int looks_like_command_line_option(const char *str)
1266+
{
1267+
return str && str[0] == '-';
1268+
}
1269+
12651270
char *xdg_config_home(const char *filename)
12661271
{
12671272
const char *home, *config_home;

0 commit comments

Comments
 (0)