git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Validate nicknames of remote branches to prohibit confusing ones
@ 2008-02-15 19:14 Daniel Barkalow
  2008-02-15 22:22 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Barkalow @ 2008-02-15 19:14 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

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>
---
I was sort of expecting you to just put this in yourself, but since you 
haven't, I wrote it up as an actual patch and fixed the polarity of the 
test for slashes.

 remote.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/remote.c b/remote.c
index 20abbc0..6b56473 100644
--- a/remote.c
+++ b/remote.c
@@ -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;
@@ -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)
-- 
1.5.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-02-16  8:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-15 19:14 [PATCH] Validate nicknames of remote branches to prohibit confusing ones Daniel Barkalow
2008-02-15 22:22 ` Junio C Hamano
2008-02-16  3:11   ` Daniel Barkalow
2008-02-16  8:08     ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).