@matheusbsbs / matheus-bagliano / commits / df93e33c8b
Fork 0

Validate nicknames of remote branches to prohibit confusing ones

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>

Daniel Barkalow committed Feb 15, 2008 at 14:14 UTC df93e33c8bc8c79751a45d8005c6a92b18d4ba6d
1 file changed +11 -1
remote.c
+11 -1
@@ -343,6 +343,16 @@ struct refspec *parse_ref_spec(int nr_refspec, const char **refspec)
343 return rs;
344 }
345
346 +static int valid_remote_nick(const char *name)
347 +{
348 + if (!name[0] || /* not empty */
349 + (name[0] == '.' && /* not "." */
350 + (!name[1] || /* not ".." */
351 + (name[1] == '.' && !name[2]))))
352 + return 0;
353 + return !strchr(name, '/'); /* no slash */
354 +}
355 +
356 struct remote *remote_get(const char *name)
357 {
358 struct remote *ret;
@@ -351,7 +361,7 @@ struct remote *remote_get(const char *name)
361 if (!name)
362 name = default_remote_name;
363 ret = make_remote(name, 0);
354 - if (name[0] != '/') {
364 + if (valid_remote_nick(name)) {
365 if (!ret->url)
366 read_remotes_file(ret);
367 if (!ret->url)