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

[PATCH 09/14] fetch: defensive programming

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
May 15, 2025, 12:45 UTC
Message-ID
<d8397662bcf72445dd06a09a6615b066c9166cf4.1747313140.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1890.git.1747313139.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>
CodeQL points out that `branch_get()` can return NULL values.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin/fetch.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 95fd0018b981..e7523c531407 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -553,7 +553,7 @@ static struct ref *get_ref_map(struct remote *remote,
 		if (remote &&
 		    (remote->fetch.nr ||
 		     /* Note: has_merge implies non-NULL branch->remote_name */
-		     (has_merge && !strcmp(branch->remote_name, remote->name)))) {
+		     (has_merge && branch && !strcmp(branch->remote_name, remote->name)))) {
 			for (i = 0; i < remote->fetch.nr; i++) {
 				get_fetch_map(remote_refs, &remote->fetch.items[i], &tail, 0);
 				if (remote->fetch.items[i].dst &&
@@ -571,6 +571,7 @@ static struct ref *get_ref_map(struct remote *remote,
 			 * Note: has_merge implies non-NULL branch->remote_name
 			 */
 			if (has_merge &&
+			    branch &&
 			    !strcmp(branch->remote_name, remote->name))
 				add_merge_config(&ref_map, remote_refs, branch, &tail);
 		} else if (!prefetch) {
-- 
gitgitgadget
Previous: Johannes Schindelin via GitGitGadgetNext: Johannes Schindelin via GitGitGadget
Message 14 of 19 in “Some defensive programming”
  1. 00/14 Some defensive programmingJohannes Schindelin via GitGitGadget, May 15, 2025
  2. 01/14 revision: defensive programmingJohannes Schindelin via GitGitGadget, May 15, 2025
  3. Junio C HamanoMay 15, 2025
  4. 02/14 get_parent(): defensive programmingJohannes Schindelin via GitGitGadget, May 15, 2025
  5. Junio C HamanoMay 15, 2025
  6. Jeff KingMay 15, 2025
  7. 03/14 fetch-pack: defensive programmingJohannes Schindelin via GitGitGadget, May 15, 2025
  8. Junio C HamanoMay 15, 2025
  9. 04/14 unparse_commit(): defensive programmingJohannes Schindelin via GitGitGadget, May 15, 2025
  10. 05/14 verify_commit_graph(): defensive programmingJohannes Schindelin via GitGitGadget, May 15, 2025
  11. 06/14 stash: defensive programmingJohannes Schindelin via GitGitGadget, May 15, 2025
  12. 07/14 stash: defensive programmingJohannes Schindelin via GitGitGadget, May 15, 2025
  13. 08/14 push: defensive programmingJohannes Schindelin via GitGitGadget, May 15, 2025
  14. 09/14 fetch: defensive programmingJohannes Schindelin via GitGitGadget, May 15, 2025
  15. 10/14 describe: defensive programmingJohannes Schindelin via GitGitGadget, May 15, 2025
  16. 11/14 inherit_tracking(): defensive programmingJohannes Schindelin via GitGitGadget, May 15, 2025
  17. 12/14 submodule: check return value of `submodule_from_path()`Johannes Schindelin via GitGitGadget, May 15, 2025
  18. 13/14 test-tool repository: check return value of `lookup_commit()`Johannes Schindelin via GitGitGadget, May 15, 2025
  19. 14/14 shallow: handle missing shallow commits gracefullyJohannes Schindelin via GitGitGadget, May 15, 2025

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.