From patchwork Wed Aug 12 18:33:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Antti_Ker=C3=A4nen?= X-Patchwork-Id: 11711103 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CF7B413A4 for ; Wed, 12 Aug 2020 18:35:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 13BDC20838 for ; Wed, 12 Aug 2020 18:35:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="key not found in DNS" (0-bit key) header.d=rbx.email header.i=@rbx.email header.b="EYbltDll" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726667AbgHLSfC (ORCPT ); Wed, 12 Aug 2020 14:35:02 -0400 Received: from aibo.runbox.com ([91.220.196.211]:49956 "EHLO aibo.runbox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726447AbgHLSfB (ORCPT ); Wed, 12 Aug 2020 14:35:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rbx.email; s=selector2; h=Content-Transfer-Encoding:Content-Type:MIME-Version: Message-Id:Date:Subject:Cc:To:From; bh=yYlVbIegDHXF+39sMlqcHNq9xnzJyeOxHUp03vxjLVA=; b=EYbltDll6NV2mZEMuC1X7tydPt gkGCbyqurOtTJdMKdDt2BqCbmtR31lGjewxiGgwB64ReaPYgBmX4or08tzj+VnwA6MHM++jI0hQF7 7sdmRDom8Q86IWmeCz5Em7GftRaysJifxrUEGwjal1NiQEsvPprgpewPlzR8ZMUMiWC65IqWib+Og IJtfpWtKonCjjik99ecK7mg423DLxCRL/JdMIOq1lQ+SBsVqexyfnfBY6Wd9JaAsKNTa3qaZbBXrK qxhkSsMNT4pBYeJRYxeaBzLxy7L1MbbWgZWVOhf99WNgGtWRp/7YDKNNE7xuHusFZjCa+F3MjVtkj 7UQHwfww==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1k5vaT-0000Yx-V8; Wed, 12 Aug 2020 20:34:58 +0200 Received: by submission02.runbox with esmtpsa [Authenticated alias (932193)] (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) id 1k5vaK-0006Nn-Vl; Wed, 12 Aug 2020 20:34:49 +0200 From: =?utf-8?q?Antti_Ker=C3=A4nen?= To: git@vger.kernel.org Cc: Taylor Blau , =?utf-8?q?Antti_Ker=C3=A4nen?= , =?utf-8?q?Jussi_Ker?= =?utf-8?q?=C3=A4nen?= , Junio C Hamano , Phillip Wood , Alban Gruin , Johannes Schindelin Subject: [PATCH v2] rebase -i: Fix possibly wrong onto hash in todo Date: Wed, 12 Aug 2020 21:33:27 +0300 Message-Id: <20200812183326.224782-1-detegr@rbx.email> X-Mailer: git-send-email 2.27.0.395.g84249cff14 MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 'todo_list_write_to_file' may overwrite the static buffer, originating from 'find_unique_abbrev', that was used to store the short commit hash 'c' for "# Rebase a..b onto c" message in the todo editor. This is because the buffer that is returned from 'find_unique_abbrev' is valid until 4 more calls to `find_unique_abbrev` are made. As 'todo_list_write_to_file' calls 'find_unique_abbrev' for each rebased commit, the hash for 'c' is overwritten if there are 4 or more commits in the rebase. This behavior has been broken since its introduction. Fix by storing the short onto commit hash in a different buffer that remains valid, before calling 'todo_list_write_to_file'. Found-by: Jussi Keränen Signed-off-by: Antti Keränen --- sequencer.c | 5 +++-- t/t3404-rebase-interactive.sh | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/sequencer.c b/sequencer.c index fd7701c88a..e2007dbb8c 100644 --- a/sequencer.c +++ b/sequencer.c @@ -5178,13 +5178,14 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla struct string_list *commands, unsigned autosquash, struct todo_list *todo_list) { - const char *shortonto, *todo_file = rebase_path_todo(); + char shortonto[GIT_MAX_HEXSZ + 1]; + const char *todo_file = rebase_path_todo(); struct todo_list new_todo = TODO_LIST_INIT; struct strbuf *buf = &todo_list->buf, buf2 = STRBUF_INIT; struct object_id oid = onto->object.oid; int res; - shortonto = find_unique_abbrev(&oid, DEFAULT_ABBREV); + find_unique_abbrev_r(shortonto, &oid, DEFAULT_ABBREV); if (buf->len == 0) { struct todo_item *item = append_new_todo(todo_list); diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index 4a7d21f898..1b4fa0843e 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -1760,6 +1760,12 @@ test_expect_success 'correct error message for commit --amend after empty pick' test_i18ngrep "middle of a rebase -- cannot amend." err ' +test_expect_success 'todo has correct onto hash' ' + GIT_SEQUENCE_EDITOR=cat git rebase -i no-conflict-branch~4 no-conflict-branch >actual && + onto=$(git rev-parse --short HEAD~4) && + test_i18ngrep "^# Rebase ..* onto $onto" actual +' + # This must be the last test in this file test_expect_success '$EDITOR and friends are unchanged' ' test_editor_unchanged