Skip to content

Commit ff45c0d

Browse files
peffgitster
authored andcommitted
fast-import: fix read of uninitialized argv memory
Fast-import shares code between its command-line parser and the "option" command. To do so, it strips the "--" from any command-line options and passes them to the option parser. However, it does not confirm that the option even begins with "--" before blindly passing "arg + 2". It does confirm that the option starts with "-", so the only affected case was: git fast-import - which would read uninitialized memory after the argument. We can fix it by using skip_prefix and checking the result. As a bonus, this gets rid of some magic numbers. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ce2ecf2 commit ff45c0d

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

fast-import.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3342,18 +3342,21 @@ static void parse_argv(void)
33423342
if (*a != '-' || !strcmp(a, "--"))
33433343
break;
33443344

3345-
if (parse_one_option(a + 2))
3345+
if (!skip_prefix(a, "--", &a))
3346+
die("unknown option %s", a);
3347+
3348+
if (parse_one_option(a))
33463349
continue;
33473350

3348-
if (parse_one_feature(a + 2, 0))
3351+
if (parse_one_feature(a, 0))
33493352
continue;
33503353

3351-
if (starts_with(a + 2, "cat-blob-fd=")) {
3352-
option_cat_blob_fd(a + 2 + strlen("cat-blob-fd="));
3354+
if (skip_prefix(a, "cat-blob-fd=", &a)) {
3355+
option_cat_blob_fd(a);
33533356
continue;
33543357
}
33553358

3356-
die("unknown option %s", a);
3359+
die("unknown option --%s", a);
33573360
}
33583361
if (i != global_argc)
33593362
usage(fast_import_usage);

0 commit comments

Comments
 (0)