All of lore.kernel.org
 help / color / mirror / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: Gregory David <gregory.david@p1sec.com>, git@vger.kernel.org
Cc: ptm-dev <ptm-dev@p1sec.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: Re: [PATCH] show-branch: fix SEGFAULT when `--current` and `--reflog` together
Date: Wed, 20 Apr 2022 11:04:11 +0100	[thread overview]
Message-ID: <0825f153-1d03-feb4-1e34-4aaed766deb0@gmail.com> (raw)
In-Reply-To: <a36fd2b0-0573-b93e-a765-ce57a651934e@p1sec.com>

Hi Gregory

Thanks for working on this

On 19/04/2022 17:32, Gregory David wrote:
> If run `show-branch` with `--current` and `--reflog` simultaneously, a
> SEGFAULT appears.
> 
> The bug is that we read over the end of the `reflog_msg` array after
> having `append_one_rev()` for the current branch without supplying a
> convenient message to it.
> 
> It seems that it has been introduced in:
> Commit 1aa68d6735 (show-branch: --current includes the current branch.,
> 2006-01-11)
> 
> Signed-off-by: Gregory DAVID <gregory.david@p1sec.com>
> Thanks-to: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>   builtin/show-branch.c | 20 ++++++++++++++++++++
>   1 file changed, 20 insertions(+)
> 
> diff --git a/builtin/show-branch.c b/builtin/show-branch.c
> index e12c5e80e3..892241ce0d 100644
> --- a/builtin/show-branch.c
> +++ b/builtin/show-branch.c
> @@ -812,6 +812,26 @@ int cmd_show_branch(int ac, const char **av, const
> char *prefix)
>   		}
>   		if (!has_head) {
>   			const char *name = head;
> +			struct object_id oid;
> +			char *ref;
> +			unsigned int flags = 0;
> +			char *log_msg;
> +			char *end_log_msg;
> +			timestamp_t timestamp;
> +			int tz;
> +
> +			if (!dwim_ref(*av, strlen(*av), &oid, &ref, 0))
> +				die(_("no such ref %s"), *av);
> +			if(read_ref_at(get_main_ref_store(the_repository),
> +					ref, flags, 0, i, &oid, &log_msg,
> +					&timestamp, &tz, NULL)) {
> +				end_log_msg = strchr(log_msg, '\n');
> +				if (end_log_msg)
> +					*end_log_msg = '\0';
> +			}
> +			if(log_msg == 0 || *log_msg == '\0')
> +				log_msg = xstrfmt("(none)");
> +			reflog_msg[ref_name_cnt] = xstrfmt("(%s) (current) %s",

Do we need a bounds check here? I think we're only guaranteed that 
ref_name_cnt - 1 < MAX_REVS though I found the existing code a bit hard 
to follow

Best Wishes

Phillip

> show_date(timestamp, tz, DATE_MODE(RELATIVE)), log_msg);
>   			skip_prefix(name, "refs/heads/", &name);
>   			append_one_rev(name);
>   		}


  parent reply	other threads:[~2022-04-20 10:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-19 16:32 [PATCH] show-branch: fix SEGFAULT when `--current` and `--reflog` together Gregory David
2022-04-19 20:49 ` Ævar Arnfjörð Bjarmason
2022-04-20 10:04 ` Phillip Wood [this message]
2022-04-21 13:34 Gregory David

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=0825f153-1d03-feb4-1e34-4aaed766deb0@gmail.com \
    --to=phillip.wood123@gmail.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gregory.david@p1sec.com \
    --cc=phillip.wood@dunelm.org.uk \
    --cc=ptm-dev@p1sec.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 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.