Skip to content

Commit

Permalink
Validate nicknames of remote branches to prohibit confusing ones
Browse files Browse the repository at this point in the history
The original problem was that the parsers for configuration files were
getting confused by seeing as nicknames remotes that involved
directory-changing characters. In particular, the branches config file
for ".." was particularly mystifying on platforms that can open
directories and read odd data from them.

The validation function was written by Junio Hamano (with a typo
corrected).

Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Daniel Barkalow authored and Junio C Hamano committed Feb 15, 2008
1 parent 8ca496e commit df93e33
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,16 @@ struct refspec *parse_ref_spec(int nr_refspec, const char **refspec)
return rs;
}

static int valid_remote_nick(const char *name)
{
if (!name[0] || /* not empty */
(name[0] == '.' && /* not "." */
(!name[1] || /* not ".." */
(name[1] == '.' && !name[2]))))
return 0;
return !strchr(name, '/'); /* no slash */
}

struct remote *remote_get(const char *name)
{
struct remote *ret;
Expand All @@ -351,7 +361,7 @@ struct remote *remote_get(const char *name)
if (!name)
name = default_remote_name;
ret = make_remote(name, 0);
if (name[0] != '/') {
if (valid_remote_nick(name)) {
if (!ret->url)
read_remotes_file(ret);
if (!ret->url)
Expand Down

0 comments on commit df93e33

Please sign in to comment.