]> Kevux Git Server - rit/commitdiff
builtin/rebase: fix leaking `commit.gpgsign` value
authorPatrick Steinhardt <ps@pks.im>
Wed, 14 Aug 2024 06:52:17 +0000 (08:52 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 14 Aug 2024 17:07:58 +0000 (10:07 -0700)
In `get_replay_opts()`, we override the `gpg_sign` field that already
got populated by `sequencer_init_config()` in case the user has
"commit.gpgsign" set in their config. This creates a memory leak because
we overwrite the previously assigned value, which may have already
pointed to an allocated string.

Let's plug the memory leak by freeing the value before we overwrite it.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/rebase.c
sequencer.c
t/t3404-rebase-interactive.sh
t/t3435-rebase-gpg-sign.sh
t/t7030-verify-tag.sh

index e3a8e74..2f01d5d 100644 (file)
@@ -186,6 +186,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
        replay.committer_date_is_author_date =
                                        opts->committer_date_is_author_date;
        replay.ignore_date = opts->ignore_date;
+       free(replay.gpg_sign);
        replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt);
        replay.reflog_action = xstrdup(opts->reflog_action);
        if (opts->strategy)
index 0291920..cade9b0 100644 (file)
@@ -303,6 +303,7 @@ static int git_sequencer_config(const char *k, const char *v,
        }
 
        if (!strcmp(k, "commit.gpgsign")) {
+               free(opts->gpg_sign);
                opts->gpg_sign = git_config_bool(k, v) ? xstrdup("") : NULL;
                return 0;
        }
index f92baad..f171af3 100755 (executable)
@@ -26,6 +26,7 @@ Initial setup:
  touch file "conflict".
 '
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 . "$TEST_DIRECTORY"/lib-rebase.sh
index 6aa2aeb..6e329fe 100755 (executable)
@@ -8,6 +8,7 @@ test_description='test rebase --[no-]gpg-sign'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 . "$TEST_DIRECTORY/lib-rebase.sh"
 . "$TEST_DIRECTORY/lib-gpg.sh"
index 6f526c3..effa826 100755 (executable)
@@ -4,6 +4,7 @@ test_description='signed tag tests'
 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 . "$TEST_DIRECTORY/lib-gpg.sh"