Skip to content

Commit f2d31c6

Browse files
LemmingAvalanchegitster
authored andcommitted
column: disallow negative padding
A negative padding does not make sense and can cause errors in the memory allocator since it’s interpreted as an unsigned integer. Reported-by: Tiago Pascoal <[email protected]> Signed-off-by: Kristoffer Haugsbakk <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7adf215 commit f2d31c6

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

builtin/column.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ int cmd_column(int argc, const char **argv, const char *prefix)
4545
memset(&copts, 0, sizeof(copts));
4646
copts.padding = 1;
4747
argc = parse_options(argc, argv, prefix, options, builtin_column_usage, 0);
48+
if (copts.padding < 0)
49+
die(_("%s must be non-negative"), "--padding");
4850
if (argc)
4951
usage_with_options(builtin_column_usage, options);
5052
if (real_command || command) {

t/t9002-column.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,15 @@ EOF
196196
test_cmp expected actual
197197
'
198198

199+
test_expect_success 'padding must be non-negative' '
200+
cat >input <<\EOF &&
201+
1 2 3 4 5 6
202+
EOF
203+
cat >expected <<\EOF &&
204+
fatal: --padding must be non-negative
205+
EOF
206+
test_must_fail git column --mode=column --padding=-1 <input >actual 2>&1 &&
207+
test_cmp expected actual
208+
'
209+
199210
test_done

0 commit comments

Comments
 (0)