Skip to content

Commit e103343

Browse files
jaysoffiangitster
authored andcommitted
rev-parse: fix potential bus error with --parseopt option spec handling
A non-empty line containing no spaces should be treated by --parseopt as an option group header, but was causing a bus error. Also added a test script for rev-parse --parseopt. Signed-off-by: Jay Soffian <jaysoffian@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 1468bd4 commit e103343

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

builtin-rev-parse.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
315315
s = strchr(sb.buf, ' ');
316316
if (!s || *sb.buf == ' ') {
317317
o->type = OPTION_GROUP;
318-
o->help = xstrdup(skipspaces(s));
318+
o->help = xstrdup(skipspaces(sb.buf));
319319
continue;
320320
}
321321

t/t1502-rev-parse-parseopt.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/sh
2+
3+
test_description='test git rev-parse --parseopt'
4+
. ./test-lib.sh
5+
6+
cat > expect.err <<EOF
7+
usage: some-command [options] <args>...
8+
9+
some-command does foo and bar!
10+
11+
-h, --help show the help
12+
--foo some nifty option --foo
13+
--bar ... some cool option --bar with an argument
14+
15+
An option group Header
16+
-C [...] option C with an optional argument
17+
18+
Extras
19+
--extra1 line above used to cause a segfault but no longer does
20+
21+
EOF
22+
23+
test_expect_success 'test --parseopt help output' '
24+
git rev-parse --parseopt -- -h 2> output.err <<EOF
25+
some-command [options] <args>...
26+
27+
some-command does foo and bar!
28+
--
29+
h,help show the help
30+
31+
foo some nifty option --foo
32+
bar= some cool option --bar with an argument
33+
34+
An option group Header
35+
C? option C with an optional argument
36+
37+
Extras
38+
extra1 line above used to cause a segfault but no longer does
39+
EOF
40+
git diff expect.err output.err
41+
'
42+
43+
test_done

0 commit comments

Comments
 (0)