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

[PATCH] submodule: check for NULL return of get_submodule_ref_store()

From
Stefan Beller <sbeller@google.com>
Date
Mar 28, 2018, 18:38 UTC
Message-ID
<20180328183832.243036-1-sbeller@google.com>
In-Reply-To
<9c3c0161-f894-3368-ece2-500d0bb6f475@web.de>
From: René Scharfe <l.s.r@web.de>

If we can't find a ref store for a submodule then assume it the latter is not initialized (or was removed). Print a status line accordingly instead of causing a segmentation fault by passing NULL as the first parameter of refs_head_ref().

Reported-by: Jeremy Feusi <jeremy@feusi.co>
Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
I added a test for you.

Thanks, Stefan

 builtin/submodule--helper.c |  8 ++++++--
 t/t7400-submodule-basic.sh  | 12 ++++++++++++
 2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index ee020d4749..ae3014ac5a 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -654,9 +654,13 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
 			     displaypath);
 	} else if (!(flags & OPT_CACHED)) {
 		struct object_id oid;
+		struct ref_store *refs = get_submodule_ref_store(path);
 
-		if (refs_head_ref(get_submodule_ref_store(path),
-				  handle_submodule_head_ref, &oid))
+		if (!refs) {
+			print_status(flags, '-', path, ce_oid, displaypath);
+			goto cleanup;
+		}
+		if (refs_head_ref(refs, handle_submodule_head_ref, &oid))
 			die(_("could not resolve HEAD ref inside the "
 			      "submodule '%s'"), path);
 
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index a39e69a3eb..d8aee51603 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -821,6 +821,18 @@ test_expect_success 'moving the superproject does not break submodules' '
 	)
 '
 
+test_expect_success 'moving the submodule does not break the superproject' '
+	(
+		cd addtest2 &&
+
+		mv repo repo.bak &&
+		git submodule status >actual &&
+		grep -e "^-" -e repo actual &&
+
+		mv repo.bak repo
+	)
+'
+
 test_expect_success 'submodule add --name allows to replace a submodule with another at the same path' '
 	(
 		cd addtest2 &&
-- 
2.17.0.rc1.321.gba9d0f2565-goog
Previous: Stefan BellerNext: Eric Sunshine
Message 6 of 14 in “Re: Null pointer dereference in git-submodule”
  1. Jeremy FeusiMar 25, 2018
  2. René ScharfeMar 25, 2018
  3. Stefan BellerMar 27, 2018
  4. Junio C HamanoMar 28, 2018
  5. Stefan BellerMar 28, 2018
  6. submodule: check for NULL return of get_submodule_ref_store()Stefan Beller, Mar 28, 2018
  7. Eric SunshineMar 28, 2018
  8. Stefan BellerMar 28, 2018
  9. Eric SunshineMar 28, 2018
  10. Stefan BellerMar 28, 2018
  11. René ScharfeMar 28, 2018
  12. Stefan BellerMar 28, 2018
  13. René ScharfeMar 28, 2018
  14. Junio C HamanoMar 28, 2018

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.