git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rubén Justo" <rjusto@gmail.com>
To: Junio C Hamano <gitster@pobox.com>,
	Kristoffer Haugsbakk <code@khaugsbakk.name>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v3 2/2] column: guard against negative padding
Date: Tue, 13 Feb 2024 19:39:51 +0100	[thread overview]
Message-ID: <69f60c3a-ff47-4cb9-a229-6c5a36e7d9fa@gmail.com> (raw)
In-Reply-To: <xmqqcyt08fa1.fsf@gitster.g>

On 13-feb-2024 09:06:46, Junio C Hamano wrote:
> Kristoffer Haugsbakk <code@khaugsbakk.name> writes:
> 
> > Make sure that client code can’t pass in a negative padding by accident.
> >
> > Suggested-by: Rubén Justo <rjusto@gmail.com>
> > Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
> > ---
> >
> > Notes (series):
> >     Apparently these are the only publicly-visible functions that use this
> >     struct according to `column.h`.
> >
> >  column.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/column.c b/column.c
> > index ff2f0abf399..50bbccc92ee 100644
> > --- a/column.c
> > +++ b/column.c
> > @@ -182,6 +182,8 @@ void print_columns(const struct string_list *list, unsigned int colopts,
> >  {
> >  	struct column_options nopts;
> >  
> > +	if (opts && (0 > opts->padding))
> > +		BUG("padding must be non-negative");
> 
> The only two current callers may happen to be "git branch" that
> passes NULL as opts, and "git clean" that passes 2 in opts->padding,
> so this BUG() will not trigger.  Once we add new callers to this
> function, or update the current callers, this safety start to matter.
> 
> The actual breakage from a negative padding happens in layout(),
> so another option would be to have this guard there, which will
> protect us from having new callers of that function as well, or
> its caller display_table(), but these have only one caller each,
> so having the guard print_columns() here, that is the closest to
> the callers would be fine.
> 
> >  	if (!list->nr)
> >  		return;
> >  	assert((colopts & COL_ENABLE_MASK) != COL_AUTO);
> > @@ -361,6 +363,8 @@ int run_column_filter(int colopts, const struct column_options *opts)
> >  {
> >  	struct strvec *argv;
> >  
> > +	if (opts && (0 > opts->padding))
> > +		BUG("padding must be non-negative");
> 
> This one happens to be safe currently because "git tag" passes 2 in
> opts->padding, but I do not think this is needed.

At first glance, I also thought this was not necessary.

However, callers of run_column_filter() might forget to check the return
value, and the BUG() triggered by the underlying process could be buried
and ignored.  Having the BUG() here, in the same process, makes it more
noticeable.

Based on this, I'm not opposed to this change.

  reply	other threads:[~2024-02-13 18:39 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-09 14:21 git column fails (or crashes) if padding is negative Tiago Pascoal
2024-02-09 16:27 ` Kristoffer Haugsbakk
2024-02-09 17:57   ` Junio C Hamano
2024-02-11 17:08     ` Kristoffer Haugsbakk
2024-02-12 16:37       ` Junio C Hamano
2024-02-09 17:52 ` [PATCH] column: disallow negative padding Kristoffer Haugsbakk
2024-02-09 18:26   ` Kristoffer Haugsbakk
2024-02-10  9:48     ` Chris Torek
2024-02-11 17:10       ` Kristoffer Haugsbakk
2024-02-11 17:55         ` Junio C Hamano
2024-02-11 18:18           ` Kristoffer Haugsbakk
2024-02-11 19:27   ` [PATCH v2] " Kristoffer Haugsbakk
2024-02-11 22:47     ` Rubén Justo
2024-02-11 23:50       ` Rubén Justo
2024-02-12  7:05       ` Kristoffer Haugsbakk
2024-02-12 16:50       ` Kristoffer Haugsbakk
2024-02-12 21:28         ` Rubén Justo
2024-02-13 16:01     ` [PATCH v3 0/2] " Kristoffer Haugsbakk
2024-02-13 16:01       ` [PATCH v3 1/2] " Kristoffer Haugsbakk
2024-02-13 16:01       ` [PATCH v3 2/2] column: guard against " Kristoffer Haugsbakk
2024-02-13 17:06         ` Junio C Hamano
2024-02-13 18:39           ` Rubén Justo [this message]
2024-02-13 19:39             ` Junio C Hamano
2024-02-13 19:56               ` Rubén Justo
2024-02-13 20:35                 ` Kristoffer Haugsbakk
2024-02-13 20:59                   ` Junio C Hamano
2024-02-13 23:25               ` Rubén Justo
2024-02-13 23:36                 ` [PATCH] tag: error when git-column fails Rubén Justo
2024-02-14  1:35                   ` Junio C Hamano
2024-02-13 19:27       ` [PATCH v3 0/2] column: disallow negative padding Rubén Justo
2024-02-13 20:32         ` Kristoffer Haugsbakk
2024-02-13 20:58           ` 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=69f60c3a-ff47-4cb9-a229-6c5a36e7d9fa@gmail.com \
    --to=rjusto@gmail.com \
    --cc=code@khaugsbakk.name \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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).