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

[PATCH v2 2/2] Avoid a segmentation fault with renaming merges

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Nov 26, 2016, 12:48 UTC
Message-ID
<d1571a25e8f3860a2867b00994d4d6938aa602ec.1480164459.git.johannes.schindelin@gmx.de>
In-Reply-To
<cover.1480164459.git.johannes.schindelin@gmx.de>

Under very particular circumstances, merge-recursive's `add_cacheinfo()` function gets a `NULL` returned from `refresh_cache_entry()` without expecting it, and subsequently passes it to `add_cache_entry()` which consequently crashes.

Let's not crash.
This fixes https://github.com/git-for-windows/git/issues/952
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 merge-recursive.c             | 2 ++
 t/t3501-revert-cherry-pick.sh | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/merge-recursive.c b/merge-recursive.c
index 9041c2f149..609061f58a 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -235,6 +235,8 @@ static int add_cacheinfo(struct merge_options *o,
 		struct cache_entry *nce;
 
 		nce = refresh_cache_entry(ce, CE_MATCH_REFRESH | CE_MATCH_IGNORE_MISSING);
+		if (!nce)
+			return err(o, _("addinfo: '%s' is not up-to-date"), path);
 		if (nce != ce)
 			ret = add_cache_entry(nce, options);
 	}
diff --git a/t/t3501-revert-cherry-pick.sh b/t/t3501-revert-cherry-pick.sh
index d7b4251234..4f2a263b63 100755
--- a/t/t3501-revert-cherry-pick.sh
+++ b/t/t3501-revert-cherry-pick.sh
@@ -141,7 +141,7 @@ test_expect_success 'cherry-pick "-" works with arguments' '
 	test_cmp expect actual
 '
 
-test_expect_failure 'cherry-pick works with dirty renamed file' '
+test_expect_success 'cherry-pick works with dirty renamed file' '
 	test_commit to-rename &&
 	git checkout -b unrelated &&
 	test_commit unrelated &&
-- 
2.11.0.rc3.windows.1
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 8 of 11 in “Fix segmentation fault with cherry-pick”
  1. 0/2 Fix segmentation fault with cherry-pickJohannes Schindelin, Nov 25, 2016
  2. 1/2 cherry-pick: demonstrate a segmentation faultJohannes Schindelin, Nov 25, 2016
  3. Johannes SchindelinNov 26, 2016
  4. 2/2 Avoid a segmentation fault with renaming mergesJohannes Schindelin, Nov 25, 2016
  5. Johannes SchindelinNov 25, 2016
  6. 0/2 Fix segmentation fault with cherry-pickJohannes Schindelin, Nov 26, 2016
  7. 1/2 cherry-pick: demonstrate a segmentation faultJohannes Schindelin, Nov 26, 2016
  8. 2/2 Avoid a segmentation fault with renaming mergesJohannes Schindelin, Nov 26, 2016
  9. Johannes SchindelinNov 26, 2016
  10. Junio C HamanoNov 28, 2016
  11. Junio C HamanoNov 28, 2016

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.