Skip to content

Commit fc1a4ce

Browse files
committed
Merge branch 'ab/fix-strategy-opts-parsing'
The code to parse "git rebase -X<opt>" was not prepared to see an unparsable option string, which has been corrected. * ab/fix-strategy-opts-parsing: sequencer.c: fix overflow & segfault in parse_strategy_opts()
2 parents 0717a42 + 15a4cc9 commit fc1a4ce

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

sequencer.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2919,13 +2919,18 @@ static int populate_opts_cb(const char *key, const char *value, void *data)
29192919
void parse_strategy_opts(struct replay_opts *opts, char *raw_opts)
29202920
{
29212921
int i;
2922+
int count;
29222923
char *strategy_opts_string = raw_opts;
29232924

29242925
if (*strategy_opts_string == ' ')
29252926
strategy_opts_string++;
29262927

2927-
opts->xopts_nr = split_cmdline(strategy_opts_string,
2928-
(const char ***)&opts->xopts);
2928+
count = split_cmdline(strategy_opts_string,
2929+
(const char ***)&opts->xopts);
2930+
if (count < 0)
2931+
die(_("could not split '%s': %s"), strategy_opts_string,
2932+
split_cmdline_strerror(count));
2933+
opts->xopts_nr = count;
29292934
for (i = 0; i < opts->xopts_nr; i++) {
29302935
const char *arg = opts->xopts[i];
29312936

t/t3436-rebase-more-options.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,24 @@ test_expect_success 'setup' '
4040
EOF
4141
'
4242

43+
test_expect_success 'bad -X <strategy-option> arguments: unclosed quote' '
44+
cat >expect <<-\EOF &&
45+
fatal: could not split '\''--bad'\'': unclosed quote
46+
EOF
47+
test_expect_code 128 git rebase -X"bad argument\"" side main >out 2>actual &&
48+
test_must_be_empty out &&
49+
test_cmp expect actual
50+
'
51+
52+
test_expect_success 'bad -X <strategy-option> arguments: bad escape' '
53+
cat >expect <<-\EOF &&
54+
fatal: could not split '\''--bad'\'': cmdline ends with \
55+
EOF
56+
test_expect_code 128 git rebase -X"bad escape \\" side main >out 2>actual &&
57+
test_must_be_empty out &&
58+
test_cmp expect actual
59+
'
60+
4361
test_expect_success '--ignore-whitespace works with apply backend' '
4462
test_must_fail git rebase --apply main side &&
4563
git rebase --abort &&

0 commit comments

Comments
 (0)