diff options
author | Enzo Matsumiya <ematsumiya@suse.de> | 2021-11-25 03:02:39 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-11-25 03:14:10 +0300 |
commit | f917f57f40a22b64ab5354e99dbf32bb48d9fc0a (patch) | |
tree | a07ad0bc547c38dde56e6a32118db6696cd680bd /t | |
parent | e9d7761bb94f20acc98824275e317fa82436c25d (diff) |
pager: fix crash when pager program doesn't exist
When prepare_cmd() fails for, e.g., pager process setup,
child_process_clear() frees the memory in pager_process.args, but .argv
was pointed to pager_process.args.v earlier in start_command(), so it's
now a dangling pointer.
setup_pager() is then called a second time, from cmd_log_init_finish()
in this case, and any further operations using its .argv, e.g. strvec_*,
will use the dangling pointer and eventually crash. According to trivial
tests, setup_pager() is not called twice if the first call is
successful.
This patch makes sure that pager_process is properly initialized on
setup_pager(). Drop CHILD_PROCESS_INIT from its declaration since it's
no longer really necessary.
Add a test to catch possible regressions.
Reproducer:
$ git config pager.show INVALID_PAGER
$ git show $VALID_COMMIT
error: cannot run INVALID_PAGER: No such file or directory
[1] 3619 segmentation fault (core dumped) git show $VALID_COMMIT
Signed-off-by: Enzo Matsumiya <ematsumiya@suse.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't')
-rwxr-xr-x | t/t7006-pager.sh | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh index 0e7cf75435..eed680a2b1 100755 --- a/t/t7006-pager.sh +++ b/t/t7006-pager.sh @@ -786,4 +786,9 @@ test_expect_success TTY 'git returns SIGPIPE on propagated signals from pager' ' test_path_is_file pager-used ' +test_expect_success TTY 'non-existent pager doesnt cause crash' ' + test_config pager.show invalid-pager && + test_terminal git show +' + test_done |