column: guard against negative padding
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Kristoffer Haugsbakk committed
Feb 13, 2024 at 17:01 UTC
76fb807faacc38661ddb1c561ed80930699146ec
1 file changed
+4
column.c
+4
@@ -182,6 +182,8 @@ void print_columns(const struct string_list *list, unsigned int colopts,
182
{
183
struct column_options nopts;
184
185
+ if (opts && (0 > opts->padding))
186
+ BUG("padding must be non-negative");
187
if (!list->nr)
188
return;
189
assert((colopts & COL_ENABLE_MASK) != COL_AUTO);
@@ -361,6 +363,8 @@ int run_column_filter(int colopts, const struct column_options *opts)
363
{
364
struct strvec *argv;
365
366
+ if (opts && (0 > opts->padding))
367
+ BUG("padding must be non-negative");
368
if (fd_out != -1)
369
return -1;
370