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

[RFC/WIP PATCH 1/3] rerere: avoid buffer overrun

From
Elijah Newren <newren@gmail.com>
Date
Aug 6, 2018, 22:47 UTC
Message-ID
<20180806224745.8681-2-newren@gmail.com>
In-Reply-To
<20180806224745.8681-1-newren@gmail.com>

check_one_conflict() compares `i` to `active_nr` in two places to avoid buffer overruns, but left out an important third location. This has not previously been a problem, because existing merge strategies have tended to not create entries at stage #1 that do not have a corresponding entry at either stage #2 or stage #3. However, this is not guaranteed, so add a check to avoid segfaults.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 rerere.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/rerere.c b/rerere.c
index 16c8aac621..7d22fb08c7 100644
--- a/rerere.c
+++ b/rerere.c
@@ -533,7 +533,7 @@ static int check_one_conflict(int i, int *type)
 	}
 
 	*type = PUNTED;
-	while (ce_stage(active_cache[i]) == 1)
+	while (i < active_nr && ce_stage(active_cache[i]) == 1)
 		i++;
 
 	/* Only handle regular files with both stages #2 and #3 */
-- 
2.18.0.550.g44d6daf40a.dirty
Previous: Elijah NewrenNext: Junio C Hamano
Message 11 of 13 in “Two RFC/WIP series for facilitating merge conflict resolution”
  1. Elijah NewrenAug 6, 2018
  2. 0/1 Simplify handling of directory/file conflictsElijah Newren, Aug 6, 2018
  3. 1/1 merge-recursive: make file/directory conflicts easier to resolveElijah Newren, Aug 6, 2018
  4. Junio C HamanoAug 9, 2018
  5. Elijah NewrenAug 9, 2018
  6. Junio C HamanoAug 9, 2018
  7. Elijah NewrenAug 9, 2018
  8. 0/3 Modifications to handling of non-textual file merge conflictsElijah Newren, Aug 6, 2018
  9. 3/3 merge-recursive: provide more conflict hints for non-textual conflictsElijah Newren, Aug 6, 2018
  10. 2/3 merge-recursive: fix handling of submodules in modify/delete conflictsElijah Newren, Aug 6, 2018
  11. 1/3 rerere: avoid buffer overrunElijah Newren, Aug 6, 2018
  12. Junio C HamanoAug 9, 2018
  13. Elijah NewrenAug 9, 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.