public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox•com>
To: Eric Sunshine <sunshine@sunshineco•com>
Cc: git@vger•kernel.org, Karthik Nayak <karthik.188@gmail•com>
Subject: Re: [PATCH 3/3] write_sha1_file_prepare: fix buffer overrun with extra-long object type
Date: Mon, 04 May 2015 10:59:25 -0700	[thread overview]
Message-ID: <xmqqzj5krzpe.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <xmqq4mnsteb8.fsf@gitster.dls.corp.google.com> (Junio C. Hamano's message of "Mon, 04 May 2015 10:58:35 -0700")

By the way, you would notice that "if we have returnsha1, then copy
that in" bit is not in the new literally codepath but still is in
write_sha1_file().

I do not think any caller passes a NULL as return_sha1 in today's
code, which made me curious.

It turns out to be a remnant of d6d3f9d0 (This implements the new
"recursive tree" write-tree., 2005-04-09); before that change,
write_sha1_file() did not have an ability to tell the caller what
object it wrote, and Linus made it optional for the callers when he
added the return_sha1[] out parameter, but all of its callers did
want the resulting object name.

So I think it is safe and sensible to do the following change
regardless of "hash-object --literally" fix.

 sha1_file.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index c8ab069..96e813f 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -3002,9 +3002,8 @@ static int freshen_packed_object(const unsigned char *sha1)
 	return find_pack_entry(sha1, &e) && freshen_file(e.p->pack_name);
 }
 
-int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *returnsha1)
+int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1)
 {
-	unsigned char sha1[20];
 	char hdr[32];
 	int hdrlen;
 
@@ -3012,8 +3011,6 @@ int write_sha1_file(const void *buf, unsigned long len, const char *type, unsign
 	 * it out into .git/objects/??/?{38} file.
 	 */
 	write_sha1_file_prepare(buf, len, type, sha1, hdr, &hdrlen);
-	if (returnsha1)
-		hashcpy(returnsha1, sha1);
 	if (freshen_loose_object(sha1) || freshen_packed_object(sha1))
 		return 0;
 	return write_loose_object(sha1, hdr, hdrlen, buf, len, 0);

  reply	other threads:[~2015-05-04 17:59 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-04  7:25 [PATCH 0/3] hash-object crash fix and new doc and tests Eric Sunshine
2015-05-04  7:25 ` [PATCH 1/3] git-hash-object.txt: document --literally option Eric Sunshine
2015-05-04  7:25 ` [PATCH 2/3] t1007: add hash-object --literally tests Eric Sunshine
2015-05-04  7:25 ` [PATCH 3/3] write_sha1_file_prepare: fix buffer overrun with extra-long object type Eric Sunshine
2015-05-04 17:58   ` Junio C Hamano
2015-05-04 17:59     ` Junio C Hamano [this message]
2015-05-04 21:37 ` [PATCH 0/4] "hash-object --literally" fixes Junio C Hamano
2015-05-04 21:37   ` [PATCH 1/4] git-hash-object.txt: document --literally option Junio C Hamano
2015-05-04 21:37   ` [PATCH 2/4] write_sha1_file_prepare: fix buffer overrun with extra-long object type Junio C Hamano
2015-05-05  0:13     ` Eric Sunshine
2015-05-05  0:28       ` Junio C Hamano
2015-05-05 17:30       ` Junio C Hamano
2015-05-05 18:49         ` Eric Sunshine
2015-05-04 21:37   ` [PATCH 3/4] t1007: add hash-object --literally tests Junio C Hamano
2015-05-04 21:37   ` [PATCH 4/4] write_sha1_file(): do not use a separate sha1[] array 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=xmqqzj5krzpe.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=karthik.188@gmail$(echo .)com \
    --cc=sunshine@sunshineco$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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