All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: Jeff King <peff@peff.net>
Subject: Re: [PATCH] fmt-merge-msg: plug small leak of commit buffer
Date: Wed, 15 Apr 2015 14:30:17 -0700	[thread overview]
Message-ID: <xmqqa8y9jd06.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <xmqqegnljd80.fsf@gitster.dls.corp.google.com> (Junio C. Hamano's message of "Wed, 15 Apr 2015 14:25:35 -0700")

Junio C Hamano <gitster@pobox.com> writes:

> A broken or badly formatted commit might not record author or
> committer lines; the function record_person() returned after
> calling get_commit_buffer() without calling unuse_commit_buffer()
> on the memory, potentially leaking it.
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>
>  * to be applied on bc6b8fc1 (use get_commit_buffer everywhere,
>    2014-06-10)

I spoke too soon.  There are two error-exit paths in this function.

-- >8 --
A broken or badly formatted commit might not record author or
committer lines or we may not find a valid name on them.  The
function record_person() returned after calling get_commit_buffer()
without calling unuse_commit_buffer() on the memory it obtained in
such cases, potentially leaking it.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/fmt-merge-msg.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index 01f6d59..76277d1 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -239,7 +239,7 @@ static void record_person(int which, struct string_list *people,
 	buffer = get_commit_buffer(commit);
 	name = strstr(buffer, field);
 	if (!name)
-		return;
+		goto leave;
 	name += strlen(field);
 	name_end = strchrnul(name, '<');
 	if (*name_end)
@@ -247,9 +247,8 @@ static void record_person(int which, struct string_list *people,
 	while (isspace(*name_end) && name <= name_end)
 		name_end--;
 	if (name_end < name)
-		return;
+		goto leave;
 	name_buf = xmemdupz(name, name_end - name + 1);
-	unuse_commit_buffer(commit, buffer);
 
 	elem = string_list_lookup(people, name_buf);
 	if (!elem) {
@@ -258,6 +257,8 @@ static void record_person(int which, struct string_list *people,
 	}
 	elem->util = (void*)(util_as_integral(elem) + 1);
 	free(name_buf);
+leave:
+	unuse_commit_buffer(commit, buffer);
 }
 
 static int cmp_string_list_util_as_integral(const void *a_, const void *b_)
-- 
2.4.0-rc2-173-gefc434b

  reply	other threads:[~2015-04-15 21:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-15 21:25 [PATCH] fmt-merge-msg: plug small leak of commit buffer Junio C Hamano
2015-04-15 21:30 ` Junio C Hamano [this message]
2015-04-15 22:14   ` Jeff King
2015-04-20 21:35     ` 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=xmqqa8y9jd06.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.