summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-02-26 18:10:25 -0800
committerJunio C Hamano <gitster@pobox.com>2024-02-26 18:10:25 -0800
commitcf258a9e4ef389277dfc2ddb0ec91fd13cead55f (patch)
tree151f76bf0c79164785db4173cee4554cf07d5df8
parent225f892685e18b917d9827bb42e9533545a98b8e (diff)
parent76fb807faacc38661ddb1c561ed80930699146ec (diff)
Merge branch 'kh/column-reject-negative-padding'
"git column" has been taught to reject negative padding value, as it would lead to nonsense behaviour including division by zero. * kh/column-reject-negative-padding: column: guard against negative padding column: disallow negative padding
-rw-r--r--builtin/column.c2
-rw-r--r--column.c4
-rwxr-xr-xt/t9002-column.sh11
3 files changed, 17 insertions, 0 deletions
diff --git a/builtin/column.c b/builtin/column.c
index e80218f81f..10ff7e0166 100644
--- a/builtin/column.c
+++ b/builtin/column.c
@@ -45,6 +45,8 @@ int cmd_column(int argc, const char **argv, const char *prefix)
memset(&copts, 0, sizeof(copts));
copts.padding = 1;
argc = parse_options(argc, argv, prefix, options, builtin_column_usage, 0);
+ if (copts.padding < 0)
+ die(_("%s must be non-negative"), "--padding");
if (argc)
usage_with_options(builtin_column_usage, options);
if (real_command || command) {
diff --git a/column.c b/column.c
index ff2f0abf39..50bbccc92e 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");
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");
if (fd_out != -1)
return -1;
diff --git a/t/t9002-column.sh b/t/t9002-column.sh
index 348cc40658..d5b98e615b 100755
--- a/t/t9002-column.sh
+++ b/t/t9002-column.sh
@@ -196,4 +196,15 @@ EOF
test_cmp expected actual
'
+test_expect_success 'padding must be non-negative' '
+ cat >input <<\EOF &&
+1 2 3 4 5 6
+EOF
+ cat >expected <<\EOF &&
+fatal: --padding must be non-negative
+EOF
+ test_must_fail git column --mode=column --padding=-1 <input >actual 2>&1 &&
+ test_cmp expected actual
+'
+
test_done