git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rerere: avoid buffer overrun
@ 2018-09-05 17:56 Elijah Newren
  2018-09-11 18:55 ` [PATCHv2 0/2] Fix rerere segfault with specially crafted merge Elijah Newren
  0 siblings, 1 reply; 5+ messages in thread
From: Elijah Newren @ 2018-09-05 17:56 UTC (permalink / raw)
  To: git; +Cc: gitster, Elijah Newren

check_one_conflict() compares `i` to `active_nr` in two places to avoid
buffer overruns, but left out an important third location.

Note that this bug probably cannot be triggered in the current codebase.
Existing merge strategies have tended not to create entries at stage #1
that do not have a corresponding entry at either stage #2 or stage #3.
(The bug was found while exploring some ideas for modifying conflict
resolution.)  However, it is technically possible that an external merge
strategy could create such entries, so add a check to avoid segfaults.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
Originally submitted here:
  https://public-inbox.org/git/20180806224745.8681-2-newren@gmail.com/
While I want to push that RFC series more and will get back to it, this
patch is independently good so I'm submitting separately.

For some history about how the current code got to where it is today, see:
  fb70a06da2f1 ("rerere: fix an off-by-one non-bug", 2015-06-28)
  5eda906b2873 ("rerere: handle conflicts with multiple stage #1 entries", 2015-07-24)

 rerere.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/rerere.c b/rerere.c
index c7787aa07f..783d4dae2a 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.19.0.rc2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-09-11 20:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-05 17:56 [PATCH] rerere: avoid buffer overrun Elijah Newren
2018-09-11 18:55 ` [PATCHv2 0/2] Fix rerere segfault with specially crafted merge Elijah Newren
2018-09-11 18:55   ` [PATCHv2 1/2] t4200: demonstrate rerere segfault on " Elijah Newren
2018-09-11 18:55   ` [PATCHv2 2/2] rerere: avoid buffer overrun Elijah Newren
2018-09-11 20:45     ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).