sequencer: assign only free()able strings to gpg_sign
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Fri, 22 Dec 2017 11:50:50 +0000 (12:50 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 22 Dec 2017 21:34:28 +0000 (13:34 -0800)
The gpg_sign member of the replay_opts structure is of type `char *`,
meaning that the sequencer deems the string to which gpg_sign points to
be under its custody, i.e. it needs to be free()d by the sequencer.

Therefore, let's only assign malloc()ed buffers to it.

Reported-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sequencer.c
t/t3404-rebase-interactive.sh
index 7051b20b76292e3b539875f0dc38108a734d2164..1b2599668f5d0288f012f83a1d2eeae541c5327d 100644 (file)
@@ -160,7 +160,7 @@ static int git_sequencer_config(const char *k, const char *v, void *cb)
        }
 
        if (!strcmp(k, "commit.gpgsign")) {
-               opts->gpg_sign = git_config_bool(k, v) ? "" : NULL;
+               opts->gpg_sign = git_config_bool(k, v) ? xstrdup("") : NULL;
                return 0;
        }
 
index 9ed0a244e6cdf34c7caca8232f0c0a8cf4864c42..040ef1a4dbc48a153d279614a75cdf8d923c9a28 100755 (executable)
@@ -1318,6 +1318,16 @@ test_expect_success 'editor saves as CR/LF' '
 
 SQ="'"
 test_expect_success 'rebase -i --gpg-sign=<key-id>' '
+       test_when_finished "test_might_fail git rebase --abort" &&
+       set_fake_editor &&
+       FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" HEAD^ \
+               >out 2>err &&
+       test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err
+'
+
+test_expect_success 'rebase -i --gpg-sign=<key-id> overrides commit.gpgSign' '
+       test_when_finished "test_might_fail git rebase --abort" &&
+       test_config commit.gpgsign true &&
        set_fake_editor &&
        FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" HEAD^ \
                >out 2>err &&