git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Validate nicknames of remote branches to prohibit confusing ones

From
Daniel Barkalow <barkalow@iabervon.org>
Date
Feb 15, 2008, 19:14 UTC
Message-ID
<alpine.LNX.1.00.0802151412390.13593@iabervon.org>

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
Next: Junio C Hamano
Message 1 of 4 in “Validate nicknames of remote branches to prohibit confusing ones”
  1. Validate nicknames of remote branches to prohibit confusing onesDaniel Barkalow, Feb 15, 2008
  2. Junio C HamanoFeb 15, 2008
  3. Daniel BarkalowFeb 16, 2008
  4. Junio C HamanoFeb 16, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.