From patchwork Fri Jan 18 09:50:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Perry via GitGitGadget X-Patchwork-Id: 10769643 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CB5C291E for ; Fri, 18 Jan 2019 09:50:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B84912A1B1 for ; Fri, 18 Jan 2019 09:50:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ACAC62E836; Fri, 18 Jan 2019 09:50:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02F5B2A1B1 for ; Fri, 18 Jan 2019 09:50:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726985AbfARJuT (ORCPT ); Fri, 18 Jan 2019 04:50:19 -0500 Received: from mail-ed1-f68.google.com ([209.85.208.68]:36015 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725856AbfARJuT (ORCPT ); Fri, 18 Jan 2019 04:50:19 -0500 Received: by mail-ed1-f68.google.com with SMTP id f23so10673352edb.3 for ; Fri, 18 Jan 2019 01:50:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:in-reply-to:references:from:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=KpFm82n9lrLA4Qg8gsgsd0bZUqfkKNIt2nIKUghqvYA=; b=gR9BQgf8sS+KNXsJSKVKDgyLW0GmvnbnqzIy/qFLkyWctH7F2VCNEzQFR+ZMZtJUbR v6VJdSERFYMLnaEF5++BVPXv4MmHXYI3rVnWbY5A65AoaFVrNnL+akMBoD/S1SFOVtvf MpwjV+QU0Y/SDUEndrNI+1u5gnf9cCdEXL2Nf7a4esWmhFvu1Y7V1CusS32e3v6blaNv wBMyoi1r3zstgWDSsgvJsuJxm1Uolz/W4TTERSv2EUhtbxyuFz5OXwj33oTLySGVJZV6 t/lDsAAd3NV5LzNaDzkx7czZ9owftpXn/z3olPGKYx5s9RfwYUmcDjjQ0eW6haAEzhqN mzuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:in-reply-to:references:from :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=KpFm82n9lrLA4Qg8gsgsd0bZUqfkKNIt2nIKUghqvYA=; b=dvsmBZbKmYtrkNSe6yWFifNk87qMkO0FUILlV2eLACY2apwlFJsLkIggtSEcsAYYMB gYcNcQbIpWtqoV8KCukLBnIbfuHQ98POunHxQ9KBsILkODZGlX8R9A3B0U3vusmRR2T9 l5ZyGjzC5TBFwT4KVwRbRpKW3866gbwDtGsGUzXqQMeJt4A6JzygMjRKRrmLc8DToMqq aYWvsTMuhuorC0s4sQeuatZlx7PlGN+wp81g/5BPvcGHwyxoHwaWSk2CRFN2zxMy5v4J yJzPu94CkD3uG+9qRMP7NO1DPnZVwu7bPCrUuZ1vlmMyGK+cbaECLHN4n5wpuEXcvUu1 HbuA== X-Gm-Message-State: AJcUukddPv7Z7E55ZhsKf6UM2tz88bTqYZGGjbJ5uJz4blnfH31j/dGJ jDLEbG3HFMXIyeE85odGzia3Iv2w X-Google-Smtp-Source: ALg8bN47dKRexw46TRjfhkKwbVujBHM6z6U7H2+92ji1xYTNxFTYQAQnZLcyuqPxp1r4hEzIf1ndIg== X-Received: by 2002:a50:d6c5:: with SMTP id l5mr15234231edj.145.1547805017344; Fri, 18 Jan 2019 01:50:17 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r23-v6sm3915270eji.64.2019.01.18.01.50.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 01:50:16 -0800 (PST) Date: Fri, 18 Jan 2019 01:50:16 -0800 (PST) X-Google-Original-Date: Fri, 18 Jan 2019 09:50:15 GMT Message-Id: In-Reply-To: References: From: "Matthew Kraai via GitGitGadget" Subject: [PATCH 1/1] stash: fix segmentation fault when files were added with intent Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Paul-Sebastian Ungureanu , Junio C Hamano , Matthew Kraai Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Matthew Kraai After `git add -N `, the index is in a special state. A state for which the built-in stash was not prepared, as it failed to initialize the `rev` structure in that case before using `&rev.pending`. Detailed explanation: If `reset_tree()` returns a non-zero value, `stash_working_tree()` calls `object_array_clear()` with `&rev.pending`. If `rev` is not initialized, this causes a segmentation fault. Prevent this by initializing `rev` before calling `reset_tree()`. This fixes https://github.com/git-for-windows/git/issues/2006. [jes: modified the commit message in preparation for sending this patch to the Git mailing list.] Signed-off-by: Matthew Kraai Signed-off-by: Johannes Schindelin --- builtin/stash.c | 3 ++- t/t3903-stash.sh | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/builtin/stash.c b/builtin/stash.c index 3ee8a41cda..74e6ff62b5 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -1048,6 +1048,8 @@ static int stash_working_tree(struct stash_info *info, struct pathspec ps) struct strbuf diff_output = STRBUF_INIT; struct index_state istate = { NULL }; + init_revisions(&rev, NULL); + set_alternate_index_output(stash_index_path.buf); if (reset_tree(&info->i_tree, 0, 0)) { ret = -1; @@ -1055,7 +1057,6 @@ static int stash_working_tree(struct stash_info *info, struct pathspec ps) } set_alternate_index_output(NULL); - init_revisions(&rev, NULL); rev.prune_data = ps; rev.diffopt.output_format = DIFF_FORMAT_CALLBACK; rev.diffopt.format_callback = add_diff_to_buf; diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index b67d7a1120..7dfa3a8038 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -287,6 +287,14 @@ test_expect_success 'stash an added file' ' test new = "$(cat file3)" ' +test_expect_success 'stash --intent-to-add file' ' + git reset --hard && + echo new >file4 && + git add --intent-to-add file4 && + test_when_finished "git rm -f file4" && + test_must_fail git stash +' + test_expect_success 'stash rm then recreate' ' git reset --hard && git rm file &&