git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 2/2] column: guard against negative padding

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 13, 2024, 17:06 UTC
Message-ID
<xmqqcyt08fa1.fsf@gitster.g>
In-Reply-To
<9355fc98e3dac5768ecaf9e179be2f7a0e74d633.1707839454.git.code@khaugsbakk.name>
Kristoffer Haugsbakk <code@khaugsbakk.name> writes:
Show 23 quoted lines
> 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.

Show 9 quoted lines
>  	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.

We will pass these through to "git column" and the negative padding will be caught as an error there anyway, no? So whether "git tag" is updated or a new caller of run_column_filter() is added, the developer will already notice it (and they will have to protect themselves just like the [1/2] of your series did for "git column" itself).

>  	if (fd_out != -1)
>  		return -1;
Previous: Kristoffer HaugsbakkNext: Rubén Justo
Message 21 of 32 in “git column fails (or crashes) if padding is negative”
  1. Tiago PascoalFeb 9, 2024
  2. Kristoffer HaugsbakkFeb 9, 2024
  3. Junio C HamanoFeb 9, 2024
  4. Kristoffer HaugsbakkFeb 11, 2024
  5. Junio C HamanoFeb 12, 2024
  6. column: disallow negative paddingKristoffer Haugsbakk, Feb 9, 2024
  7. Kristoffer HaugsbakkFeb 9, 2024
  8. Chris TorekFeb 10, 2024
  9. Kristoffer HaugsbakkFeb 11, 2024
  10. Junio C HamanoFeb 11, 2024
  11. Kristoffer HaugsbakkFeb 11, 2024
  12. column: disallow negative paddingKristoffer Haugsbakk, Feb 11, 2024
  13. Rubén JustoFeb 11, 2024
  14. Rubén JustoFeb 11, 2024
  15. Kristoffer HaugsbakkFeb 12, 2024
  16. Kristoffer HaugsbakkFeb 12, 2024
  17. Rubén JustoFeb 12, 2024
  18. 0/2 column: disallow negative paddingKristoffer Haugsbakk, Feb 13, 2024
  19. 1/2 column: disallow negative paddingKristoffer Haugsbakk, Feb 13, 2024
  20. 2/2 column: guard against negative paddingKristoffer Haugsbakk, Feb 13, 2024
  21. Junio C HamanoFeb 13, 2024
  22. Rubén JustoFeb 13, 2024
  23. Junio C HamanoFeb 13, 2024
  24. Rubén JustoFeb 13, 2024
  25. Kristoffer HaugsbakkFeb 13, 2024
  26. Junio C HamanoFeb 13, 2024
  27. Rubén JustoFeb 13, 2024
  28. tag: error when git-column failsRubén Justo, Feb 13, 2024
  29. Junio C HamanoFeb 14, 2024
  30. Rubén JustoFeb 13, 2024
  31. Kristoffer HaugsbakkFeb 13, 2024
  32. Junio C HamanoFeb 13, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.