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

[PATCH 7/6] builtin-remote: guard remote->url accesses by remote->url_nr check

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Dec 5, 2007, 21:40 UTC
Message-ID
<Pine.LNX.4.64.0712052139560.27959@racer.site>
In-Reply-To
<Pine.LNX.4.64.0712051902080.27959@racer.site>

struct remote's url member is not a NULL terminated list. Instead, we have to check url_nr before accessing it.

Noticed by Johannes Sixt.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
	For your viewing pleasure, this is not a resend, but an amend.  
	Feel free to squash with 4/6, or to bug me to do it.
 builtin-remote.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/builtin-remote.c b/builtin-remote.c
index 142eb97..ea323e2 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -356,7 +356,8 @@ static int show_or_prune(int argc, const char **argv, int prune)
 		states.remote = remote_get(*argv);
 		if (!states.remote)
 			return error("No such remote: %s", *argv);
-		transport = transport_get(NULL, states.remote->url[0]);
+		transport = transport_get(NULL, states.remote->url_nr > 0 ?
+			states.remote->url[0] : NULL);
 		ref = transport_get_remote_refs(transport);
 
 		read_branches();
@@ -391,7 +392,7 @@ static int show_or_prune(int argc, const char **argv, int prune)
 		}
 
 		printf("* remote %s\n  URL: %s\n", *argv,
-			states.remote->url[0] ?
+			states.remote->url_nr > 0 ?
 				states.remote->url[0] : "(no URL)");
 
 		for (i = 0; i < branch_list.nr; i++) {
@@ -468,8 +469,9 @@ static int get_one_entry(struct remote *remote, void *priv)
 {
 	struct path_list *list = priv;
 
-	path_list_append(remote->name, list)->util = (void *)remote->url[0];
-	if (remote->url[0] && remote->url[1])
+	path_list_append(remote->name, list)->util = remote->url_nr ?
+		(void *)remote->url[0] : NULL;
+	if (remote->url_nr > 1)
 		warning ("Remote %s has more than one URL", remote->name);
 
 	return 0;
-- 
1.5.3.7.2157.g9598e
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 10 of 14 in “builtin-remote”
  1. 0/6 builtin-remoteJohannes Schindelin, Dec 5, 2007
  2. (unknown)Johannes Schindelin, Dec 5, 2007
  3. Johannes SchindelinDec 5, 2007
  4. 1/6 path-list: add functions to work with unsorted listsJohannes Schindelin, Dec 5, 2007
  5. 2/6 parseopt: add flag to stop on first non optionJohannes Schindelin, Dec 5, 2007
  6. 3/6 Test "git remote show" and "git remote prune"Johannes Schindelin, Dec 5, 2007
  7. René ScharfeDec 5, 2007
  8. Johannes SchindelinDec 5, 2007
  9. 4/6 Make git-remote a builtinJohannes Schindelin, Dec 5, 2007
  10. 7/6 builtin-remote: guard remote->url accesses by remote->url_nr checkJohannes Schindelin, Dec 5, 2007
  11. 5/6 builtin-remote: prune remotes correctly that were added with --mirrorJohannes Schindelin, Dec 5, 2007
  12. 6/6 DWIM "git add remote ..."Johannes Schindelin, Dec 5, 2007
  13. Linus TorvaldsDec 5, 2007
  14. Johannes SchindelinDec 5, 2007

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.