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 <tiago@pascoal.net> 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
f2d31c69ce38e4515d5dfac34c69423c833b85f9
2 files changed
+13
builtin/column.c
+2
@@ -45,6 +45,8 @@ int cmd_column(int argc, const char **argv, const char *prefix)
45
memset(&copts, 0, sizeof(copts));
46
copts.padding = 1;
47
argc = parse_options(argc, argv, prefix, options, builtin_column_usage, 0);
48
+ if (copts.padding < 0)
49
+ die(_("%s must be non-negative"), "--padding");
50
if (argc)
51
usage_with_options(builtin_column_usage, options);
52
if (real_command || command) {
t/t9002-column.sh
+11
@@ -196,4 +196,15 @@ EOF
196
test_cmp expected actual
197
'
198
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
+
210
test_done