git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Derrick Stolee <dstolee@microsoft.com>
To: git@vger.kernel.org
Cc: peff@peff.net, stolee@gmail.com, christian.couder@gmail.com,
	Derrick Stolee <dstolee@microsoft.com>
Subject: [PATCH v2] sha1_name: fix uninitialized memory errors
Date: Tue, 27 Feb 2018 06:47:04 -0500	[thread overview]
Message-ID: <20180227114704.193145-1-dstolee@microsoft.com> (raw)
In-Reply-To: <20180226204151.GA12598@sigill.intra.peff.net>

Peff made an excellent point about the nested if statements. This
goes back to Christian's original recommendation.

-- >8 --

During abbreviation checks, we navigate to the position within a
pack-index that an OID would be inserted and check surrounding OIDs
for the maximum matching prefix. This position may be beyond the
last position, because the given OID is lexicographically larger
than every OID in the pack. Then nth_packed_object_oid() does not
initialize "oid".

Use the return value of nth_packed_object_oid() to prevent these
errors.

Reported-by: Christian Couder <christian.couder@gmail.com>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
 sha1_name.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/sha1_name.c b/sha1_name.c
index 611c7d24dd..a041d8d24f 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -547,15 +547,15 @@ static void find_abbrev_len_for_pack(struct packed_git *p,
 	 */
 	mad->init_len = 0;
 	if (!match) {
-		nth_packed_object_oid(&oid, p, first);
-		extend_abbrev_len(&oid, mad);
+		if (nth_packed_object_oid(&oid, p, first))
+			extend_abbrev_len(&oid, mad);
 	} else if (first < num - 1) {
-		nth_packed_object_oid(&oid, p, first + 1);
-		extend_abbrev_len(&oid, mad);
+		if (nth_packed_object_oid(&oid, p, first + 1))
+			extend_abbrev_len(&oid, mad);
 	}
 	if (first > 0) {
-		nth_packed_object_oid(&oid, p, first - 1);
-		extend_abbrev_len(&oid, mad);
+		if (nth_packed_object_oid(&oid, p, first - 1))
+			extend_abbrev_len(&oid, mad);
 	}
 	mad->init_len = mad->cur_len;
 }
-- 
2.16.2.265.g3d5930c0b9.dirty


  reply	other threads:[~2018-02-27 11:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-26  9:04 Use of uninitialised value of size 8 in sha1_name.c Christian Couder
2018-02-26  9:53 ` Jeff King
2018-02-26 10:23   ` Christian Couder
2018-02-26 14:06     ` Derrick Stolee
2018-02-26 14:43       ` Christian Couder
2018-02-26 14:56         ` [PATCH] sha1_name: fix uninitialized memory errors Derrick Stolee
2018-02-26 20:41           ` Jeff King
2018-02-27 11:47             ` Derrick Stolee [this message]
2018-02-27 21:33               ` [PATCH v2] " Jeff King
2018-02-27 22:30                 ` Junio C Hamano
2018-02-27 22:40                   ` Jeff King
2018-02-28 20:50               ` Junio C Hamano
2018-02-28 20:57                 ` Derrick Stolee
2018-02-28 21:06                   ` 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

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

  git send-email \
    --in-reply-to=20180227114704.193145-1-dstolee@microsoft.com \
    --to=dstolee@microsoft.com \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    --cc=stolee@gmail.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.
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).