public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Toon Claes <toon@iotcl.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] bundle-uri: plug leak in unbundle_from_file()
Date: Mon, 26 Aug 2024 11:51:00 +0200	[thread overview]
Message-ID: <ZsxQBEpfChQozhF7@tanuki> (raw)
In-Reply-To: <20240826083052.1542228-1-toon@iotcl.com>

On Mon, Aug 26, 2024 at 10:30:52AM +0200, Toon Claes wrote:
> When the function returns early, the variable bundle_ref is not released
> through strbuf_release().
> 
> Fix this leak. And while at it, remove assignments in the conditions of
> the "if" statements as suggested in the CodingGuidelines.
> 
> Signed-off-by: Toon Claes <toon@iotcl.com>
> ---
>  bundle-uri.c | 16 +++++++++++-----
>  1 file changed, 11 insertions(+), 5 deletions(-)
> 
> diff --git a/bundle-uri.c b/bundle-uri.c
> index 1e0ee156ba..eb49cba182 100644
> --- a/bundle-uri.c
> +++ b/bundle-uri.c
> @@ -367,17 +367,21 @@ static int unbundle_from_file(struct repository *r, const char *file)
>  	struct strbuf bundle_ref = STRBUF_INIT;
>  	size_t bundle_prefix_len;
> 
> -	if ((bundle_fd = read_bundle_header(file, &header)) < 0)
> -		return 1;
> +	bundle_fd = read_bundle_header(file, &header);
> +	if (bundle_fd < 0) {
> +		result = 1;
> +		goto cleanup;
> +	}
> 
>  	/*
>  	 * Skip the reachability walk here, since we will be adding
>  	 * a reachable ref pointing to the new tips, which will reach
>  	 * the prerequisite commits.
>  	 */
> -	if ((result = unbundle(r, &header, bundle_fd, NULL,
> -			       VERIFY_BUNDLE_QUIET | (fetch_pack_fsck_objects() ? VERIFY_BUNDLE_FSCK : 0))))
> -		return 1;
> +	result = unbundle(r, &header, bundle_fd, NULL,
> +			  VERIFY_BUNDLE_QUIET | (fetch_pack_fsck_objects() ? VERIFY_BUNDLE_FSCK : 0));
> +	if (result)
> +		goto cleanup;

This changes the returned error code from `1` to whatever `unbundle()`
returns. Is this intentional? If so, the commit message should explain
why this change is safe.

Other than that this looks good to me, and the fix does not conflict
with any of my leak-plugging series.

Thanks!

Patrick

  reply	other threads:[~2024-08-26  9:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-26  8:30 [PATCH] bundle-uri: plug leak in unbundle_from_file() Toon Claes
2024-08-26  9:51 ` Patrick Steinhardt [this message]
2024-08-26 16:06   ` Junio C Hamano
2024-10-01 18:58     ` Toon Claes
2024-10-01 19:29       ` Junio C Hamano
2024-10-10  9:15     ` Toon Claes
2024-10-10  9:12 ` [PATCH v2] " Toon Claes
2024-10-10 12:55   ` Patrick Steinhardt
2024-10-10 18:47     ` 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=ZsxQBEpfChQozhF7@tanuki \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=toon@iotcl.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