All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kristoffer Haugsbakk <code@khaugsbakk.name>
To: git@vger.kernel.org
Cc: "Kristoffer Haugsbakk" <code@khaugsbakk.name>,
	"Tiago Pascoal" <tiago@pascoal.net>,
	"Chris Torek" <chris.torek@gmail.com>,
	"Junio C Hamano" <gitster@pobox.com>,
	"Rubén Justo" <rjusto@gmail.com>
Subject: [PATCH v3 0/2] column: disallow negative padding
Date: Tue, 13 Feb 2024 17:01:19 +0100	[thread overview]
Message-ID: <cover.1707839454.git.code@khaugsbakk.name> (raw)
In-Reply-To: <1c959378cf495d7a3d70d0c7bdf08cc501ed6e5d.1707679627.git.code@khaugsbakk.name>

Fix bug in git-column(1): a user can pass a negative `padding` which
causes issues inside the memory allocator.

§ Changes in v3

Incorporate Ruben’s suggestion about guarding against negative padding
with `BUG` in `column.c` (not `builtin/column.c`). This then supersedes
Junio’s extra conditional checks since they are no longer needed. The
series gets split into two patches.

Cc: Tiago Pascoal <tiago@pascoal.net>
Cc: Chris Torek <chris.torek@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>
Cc: Rubén Justo <rjusto@gmail.com>

Kristoffer Haugsbakk (2):
  column: disallow negative padding
  column: guard against negative padding

 builtin/column.c  |  2 ++
 column.c          |  4 ++++
 t/t9002-column.sh | 11 +++++++++++
 3 files changed, 17 insertions(+)

Range-diff against v2:
1:  1c959378cf4 ! 1:  4cac42ca6f8 column: disallow negative padding
    @@ Commit message
         A negative padding does not make sense and can cause errors in the
         memory allocator since it’s interpreted as an unsigned integer.
     
    -    Disallow negative padding. Also guard against negative padding in
    -    `column.c` where it is conditionally used.
    -
         Reported-by: Tiago Pascoal <tiago@pascoal.net>
    -    Helped-by: Junio C Hamano <gitster@pobox.com>
         Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
     
    -
    - ## Notes (series) ##
    -    v2:
    -    • Incorporate Junio’s changes (guard against negative padding in
    -      `column.c`)
    -    • Tweak commit message based on Junio’s analysis
    -    • Use gettext for error message
    -      • However I noticed that the “translation string” from `fast-import`
    -        isn’t a translation string. So let’s invent a new one and use a
    -        parameter so that it can be used elsewhere.
    -    • Make a test
    -
      ## builtin/column.c ##
     @@ builtin/column.c: int cmd_column(int argc, const char **argv, const char *prefix)
      	memset(&copts, 0, sizeof(copts));
    @@ builtin/column.c: int cmd_column(int argc, const char **argv, const char *prefix
      		usage_with_options(builtin_column_usage, options);
      	if (real_command || command) {
     
    - ## column.c ##
    -@@ column.c: void print_columns(const struct string_list *list, unsigned int colopts,
    - 	memset(&nopts, 0, sizeof(nopts));
    - 	nopts.indent = opts && opts->indent ? opts->indent : "";
    - 	nopts.nl = opts && opts->nl ? opts->nl : "\n";
    --	nopts.padding = opts ? opts->padding : 1;
    -+	nopts.padding = (opts && 0 <= opts->padding) ? opts->padding : 1;
    - 	nopts.width = opts && opts->width ? opts->width : term_columns() - 1;
    - 	if (!column_active(colopts)) {
    - 		display_plain(list, "", "\n");
    -@@ column.c: int run_column_filter(int colopts, const struct column_options *opts)
    - 		strvec_pushf(argv, "--width=%d", opts->width);
    - 	if (opts && opts->indent)
    - 		strvec_pushf(argv, "--indent=%s", opts->indent);
    --	if (opts && opts->padding)
    -+	if (opts && 0 <= opts->padding)
    - 		strvec_pushf(argv, "--padding=%d", opts->padding);
    - 
    - 	fflush(stdout);
    -
      ## t/t9002-column.sh ##
     @@ t/t9002-column.sh: EOF
      	test_cmp expected actual
-:  ----------- > 2:  9355fc98e3d column: guard against negative padding
-- 
2.43.0


  parent reply	other threads:[~2024-02-13 16:02 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     ` Kristoffer Haugsbakk [this message]
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
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=cover.1707839454.git.code@khaugsbakk.name \
    --to=code@khaugsbakk.name \
    --cc=chris.torek@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=rjusto@gmail.com \
    --cc=tiago@pascoal.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.