diff options
| author | Christian Couder <christian.couder@gmail.com> | 2026-08-11 14:14:46 +0200 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-08-11 12:17:14 -0700 |
| commit | 88249755a4e9fe4bfa0868871372752158b1f9fe (patch) | |
| tree | f7b6683c383a3578518d36437c6f7e8ead62ff4b /t/t4013/diff.diff_initial..side | |
| parent | 11c6700f10234578d10523faf35656ca491425c9 (diff) | |
git: avoid segfault on "git --shallow-file" without a value
In "git.c", the other `handle_options()` options that take their value
as a separate argument, like `--git-dir`, `--namespace` or `-C`, check
that such an argument actually exists before using it, and error out
with a message and the usage string otherwise.
The `--shallow-file` option doesn't perform that check. It blindly
advances past the option and then dereferences the next element of
`argv`, which is the NULL terminator when no value was given. So
`git --shallow-file` segfaults:
$ git --shallow-file
Segmentation fault (core dumped)
Let's fix that by checking that a value was given, in the same way and
with a message worded like the ones the other options use.
While at it, let's also set the environment variable before advancing
past the option, instead of advancing first and using `(*argv)[0]`, so
that this option looks like the other ones.
Note that all the in-tree callers passing `--shallow-file` to a `git`
subprocess always pass a value after it, so they are not affected. In
`upload-pack.c` that value is an empty string, which is still accepted.
Signed-off-by: Christian Couder <christian.couder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t4013/diff.diff_initial..side')
0 files changed, 0 insertions, 0 deletions
