git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Elijah Newren <newren@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, Elijah Newren <newren@gmail.com>
Subject: [PATCH] rerere: avoid buffer overrun
Date: Wed,  5 Sep 2018 10:56:05 -0700	[thread overview]
Message-ID: <20180905175605.12341-1-newren@gmail.com> (raw)

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


             reply	other threads:[~2018-09-05 18:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-05 17:56 Elijah Newren [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180905175605.12341-1-newren@gmail.com \
    --to=newren@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).