From patchwork Thu Apr 1 08:32:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jeff King X-Patchwork-Id: 12177509 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35EC3C43460 for ; Thu, 1 Apr 2021 08:33:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E7FA361001 for ; Thu, 1 Apr 2021 08:33:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233605AbhDAIdA (ORCPT ); Thu, 1 Apr 2021 04:33:00 -0400 Received: from cloud.peff.net ([104.130.231.41]:39586 "EHLO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233509AbhDAIc0 (ORCPT ); Thu, 1 Apr 2021 04:32:26 -0400 Received: (qmail 7452 invoked by uid 109); 1 Apr 2021 08:32:25 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Thu, 01 Apr 2021 08:32:24 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 12274 invoked by uid 111); 1 Apr 2021 08:32:25 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Thu, 01 Apr 2021 04:32:25 -0400 Authentication-Results: peff.net; auth=none Date: Thu, 1 Apr 2021 04:32:24 -0400 From: Jeff King To: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason Cc: Olga Telezhnaya , Junio C Hamano , git@vger.kernel.org, Taylor Blau , Elijah Newren , Johannes Schindelin Subject: [PATCH] ref-filter: fix NULL check for parse object failure Message-ID: References: <20210308200426.21824-1-avarab@gmail.com> <87k0pnkwej.fsf@evledraar.gmail.com> <87eefvkq5d.fsf@evledraar.gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On Thu, Apr 01, 2021 at 03:54:56AM -0400, Jeff King wrote: > On Wed, Mar 31, 2021 at 10:46:22PM +0200, Ævar Arnfjörð Bjarmason wrote: > > > > Neither of those types is the correct one. And the segfault is just a > > > bonus! :) > > > > > > I'd expect similar cases with parsing commit parents and tree pointers. > > > And probably tree entries whose modes are wrong. > > > > So the segfault happens without my patches, > > Yeah, sorry if that was unclear. It is definitely a pre-existing bug. Here's a patch to fix it. This is mostly orthogonal to your patch series. It happens to use a similar recipe to reproduce, but that is not the only way to do it, and the fix and the test shouldn't conflict textually or semantically. -- >8 -- Subject: [PATCH] ref-filter: fix NULL check for parse object failure After we run parse_object_buffer() to get an object's contents, we try to check that the return value wasn't NULL. However, since our "struct object" is a pointer-to-pointer, and we assign like: *obj = parse_object_buffer(...); it's not correct to check: if (!obj) That will always be true, since our double pointer will continue to point to the single pointer (which is itself NULL). This is a regression that was introduced by aa46a0da30 (ref-filter: use oid_object_info() to get object, 2018-07-17); since that commit we'll segfault on a parse failure, as we try to look at the NULL object pointer. There are many ways a parse could fail, but most of them are hard to set up in the tests (it's easy to make a bogus object, but update-ref will refuse to point to it). The test here uses a tag which points to a wrong object type. A parse of just the broken tag object will succeed, but seeing both tag objects in the same process will lead to a parse error (since we'll see the pointed-to object as both types). Signed-off-by: Jeff King --- ref-filter.c | 2 +- t/t6300-for-each-ref.sh | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ref-filter.c b/ref-filter.c index f0bd32f714..a0adb4551d 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1608,7 +1608,7 @@ static int get_object(struct ref_array_item *ref, int deref, struct object **obj if (oi->info.contentp) { *obj = parse_object_buffer(the_repository, &oi->oid, oi->type, oi->size, oi->content, &eaten); - if (!obj) { + if (!*obj) { if (!eaten) free(oi->content); return strbuf_addf_ret(err, -1, _("parse_object_buffer failed on %s for %s"), diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index cac7f443d0..2e7c32d50c 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -1134,4 +1134,14 @@ test_expect_success 'for-each-ref --ignore-case works on multiple sort keys' ' test_cmp expect actual ' +test_expect_success 'for-each-ref reports broken tags' ' + git tag -m "good tag" broken-tag-good HEAD && + git cat-file tag broken-tag-good >good && + sed s/commit/blob/ bad && + bad=$(git hash-object -w -t tag bad) && + git update-ref refs/tags/broken-tag-bad $bad && + test_must_fail git for-each-ref --format="%(*objectname)" \ + refs/tags/broken-tag-* +' + test_done From patchwork Thu Apr 1 13:56:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12178709 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C542C433B4 for ; Thu, 1 Apr 2021 17:58:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 26A2560FF3 for ; Thu, 1 Apr 2021 17:58:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236424AbhDAR6K (ORCPT ); Thu, 1 Apr 2021 13:58:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236866AbhDARza (ORCPT ); Thu, 1 Apr 2021 13:55:30 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CC67C08EC91 for ; Thu, 1 Apr 2021 06:56:36 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id k8so1936747wrc.3 for ; Thu, 01 Apr 2021 06:56:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wKtEcRlE9pDm2vZtPKjkj+Pa8oKcdZ0UFP6zBPGIm/I=; b=L9kLRGP0YXY7lUSN1tvoSp8W+FidQGtrrqnVJmCqYJiiopHA6leOXBXCYN5exntGMC DPbKvsShNMhVQoy/Ohw9qvdj7GS8wHlhJlFVxZvkc7ts/j+PgzuLiRi8cMtZ+yexlPF5 bIXAoOjgYqS1Sq5p+uRoASfUoHbBNOPu3OiTVr4u/S3doEjhXtovvMKvH2FNgOLbBCaA NsvfrJ+F4xcum8BnxLtxt8+BrRT5W/1kPDkqmsStGTKweijXc8kn4BX6HA0Z+E/bkRhj J/zlMhiOEwale4jjJcPUv5vLZifzFvrO8SYWcFn2hm+nZ46fVFHl5nlBIkpyyNayhTyI KnaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wKtEcRlE9pDm2vZtPKjkj+Pa8oKcdZ0UFP6zBPGIm/I=; b=SYRv/bPCAYpZNe0p1xdBGDTnERFUiBbmwiy8zMieVrabNukynxOkoX32lFcq7U2zsH YSSsTTJr+fiwTZqrU6Q30G/GulL+CUan2ehXxRNshuF4Bz2zTAZ0AfDn1AHx352XSuVn EOr7hHwilqVnsJ4awjSsdETJs8MkMEKe4OkNIDsE4nck1LHn43u++/oduuXwyK203pw0 RbaPdHZ19fY4NwNZiGOk15lfESCybUUDYn4M9mF5MJhvOJkLYnRS5xDMMYSQsEyhz7uU 4D1+7pXDDoBTq6RROzVTi2FPYu7Clqly9XQi8qT+O3uKN0KnZBRUTJ1MOJbhKM7pP32E 7QAA== X-Gm-Message-State: AOAM530boxJ4ehBacBi94pXAmfBqVBPtvYM+MrABoHShwSlbMuEccMps YUGujbnEeMSvEOMMecnxQgSim7uZeIVfRg== X-Google-Smtp-Source: ABdhPJxYfCUJpFK1WtcyyA9/szt/IqPyjXjM7TZf4FbivsC9R+KKDe3mDHjOrIDXrMbMRDHrhayBuw== X-Received: by 2002:adf:8151:: with SMTP id 75mr9918551wrm.152.1617285394911; Thu, 01 Apr 2021 06:56:34 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n7sm10145770wrv.71.2021.04.01.06.56.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Apr 2021 06:56:34 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Olga Telezhnaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v2 2/5] mktag tests: invert --no-strict test Date: Thu, 1 Apr 2021 15:56:27 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.474.g72d45d12706 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the mktag --no-strict test to actually test success under --no-strict, that test was added in 06ce79152be (mktag: add a --[no-]strict option, 2021-01-06). It doesn't make sense to check that we have the same failure except when we want --no-strict, by doing that we're assuming that the behavior will be different under --no-strict, bun nothing was testing for that. We should instead assert that --strict is the same as --no-strict, except in the cases where we've declared that it's not. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t3800-mktag.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/t/t3800-mktag.sh b/t/t3800-mktag.sh index e9008744e3d..951e6d39c2a 100755 --- a/t/t3800-mktag.sh +++ b/t/t3800-mktag.sh @@ -33,6 +33,8 @@ check_verify_failure () { then test_must_fail git mktag err2 && test_cmp err err2 + else + git mktag --no-strict X-Patchwork-Id: 12178699 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3CFBC433B4 for ; Thu, 1 Apr 2021 17:53:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D4CC960FE7 for ; Thu, 1 Apr 2021 17:53:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235351AbhDARx0 (ORCPT ); Thu, 1 Apr 2021 13:53:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236070AbhDARtU (ORCPT ); Thu, 1 Apr 2021 13:49:20 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40D8EC08EC93 for ; Thu, 1 Apr 2021 06:56:38 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id e18so1920526wrt.6 for ; Thu, 01 Apr 2021 06:56:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GTM5X/k5avj5ohBB3J/UAr0QKLyPsqv39X2A1+E5YaU=; b=dXW0L9NXJ6JWa+8gXNm1zQKBKXrWj9IGNDbCw6uXxtXraRTGq7hbEDXJdvY689RMxr okQaj/m5V0HAPmWEpFitisKBGoRPAkwMO0diUhjGHno+gFO2wapmeLAyhWWtqYabzbai pQ7b35dD4QUzDZvUc0drDO5rwHPnBqa7uXkkakJMTKdE3dwI4F23IGKBNgbuBmNkYCGU UQrIG2WtwnWmVLfvf2djlLIaeveiCFUVAvSv2a2qbdaQ66JMq58WjDcXgitUVZIX0s7t XdEWOBZupQDEv38IWVmlyjvFDvneinv7Kwjd77xM3H2zTRsMA9f3IcGF7UjRstlfZlwt 6z0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GTM5X/k5avj5ohBB3J/UAr0QKLyPsqv39X2A1+E5YaU=; b=BKlR1BYJtIDFfttcWNvRC5fOQAtVigx9fZMpgXqYrE2G83Wd/oCxSTZNLY9oQWlPQW 7vlEmicDdbABTin5XgyVSeW3YY0aXEFZDEZ4M1ORWOC6qNKD/99zqO9OguZFKh2z4LBe a9O0iECeR6gO/IwjOXL+Y9QSeoCPFmLg4HeMT6PvTF6a2Nrro/xfNlv4JimyIYhrI8Ls ORoOmAY4VxTpt9/EaE/8skDQyGvwKXT8u9f8U41BoDhsHqzP8JxyaZ9Up5HPNUY6c+0L e+0QqlEuoGLWZdpGuqx8igvwyYh0d46ynMtqXhSmrvYyRwiwGicRsyneM6B2gmWh5gVm Mo+g== X-Gm-Message-State: AOAM533NxLO31EDv2b5Ul2IQkTUk7wHJP2uutDIruTxi6mwQpWxhKCt/ R8pFJ9vbEaKp/iEpe6E6yGra6nuMaw7IzA== X-Google-Smtp-Source: ABdhPJyRkOMy6p5UsDnVJRoCP4q97k60yjztL7ckEtqn55L/5vh17pFOAm3JBF83Blz4XX5kprf8yQ== X-Received: by 2002:adf:9d82:: with SMTP id p2mr9895279wre.234.1617285396756; Thu, 01 Apr 2021 06:56:36 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n7sm10145770wrv.71.2021.04.01.06.56.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Apr 2021 06:56:36 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Olga Telezhnaya , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v2 4/5] mktag tests: test for maybe segfaulting for-each-ref Date: Thu, 1 Apr 2021 15:56:29 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.474.g72d45d12706 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a test to check that "for-each-ref" fails on a repository with a bad tag, this test intentionally uses "! " instead of "test_must_fail " to hide a segfault. We'll fix the underlying bug in a subsequent commit and convert it to "test_must_fail". Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t3800-mktag.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/t/t3800-mktag.sh b/t/t3800-mktag.sh index 4673235b1fd..10e4fde28de 100755 --- a/t/t3800-mktag.sh +++ b/t/t3800-mktag.sh @@ -58,7 +58,13 @@ check_verify_failure () { # The update-ref command itself might fail, but we are # not testing that echo "$bad_tag" >"bad-tag/.git/$tag_ref" && - test_must_fail git -C bad-tag fsck + test_must_fail git -C bad-tag fsck && + + printf "%s tag\t%s\n" "$bad_tag" "$tag_ref" >expected && + git -C bad-tag for-each-ref "$tag_ref" >actual && + test_cmp expected actual && + # segfaults! + ! git -C bad-tag for-each-ref --format="%(*objectname)" ' } From patchwork Thu Apr 1 13:56:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12178697 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4812FC43460 for ; Thu, 1 Apr 2021 17:53:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1678E60FEE for ; Thu, 1 Apr 2021 17:53:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235837AbhDARxX (ORCPT ); Thu, 1 Apr 2021 13:53:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236854AbhDARrg (ORCPT ); Thu, 1 Apr 2021 13:47:36 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48DDAC08EC97 for ; Thu, 1 Apr 2021 06:56:39 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id f22-20020a7bc8d60000b029010c024a1407so2903229wml.2 for ; Thu, 01 Apr 2021 06:56:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tl6bubXoKoHJXkNLFtOaaDIbI4NaaaAehNk92OsY82E=; b=fOBSGACqEKc9PydIR5prQ15R1QV9Xr4ky3xGmkbtpiFnKH7OcX/qQg5AQ3bVVgKcZk NP+3fwXju76XW/UpVDgm/F1zCGW+wfm/ebdc6pIp9x0koRm5OoWvw/7yQrNzOjvuSsfU hVeSXc9azQ1O1L73OKfZCXABGrCWxaK61Bsiqz5mZzWWvXZ5QCsB7psZuAfR9l3U3y8l yCGk5eTvvQuz1C57j1/JMh2qw3ZZEehwGNPTpdcCQ3dczpzaFj2r2NmAtAnU5j3Joc79 6HOVCUXsf+fiVo9SH/PFkYZrXXFlFYVf0zwXRsFBEd/0P9KtOXf08tWmWQ8wE1rW7ZjO dTgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tl6bubXoKoHJXkNLFtOaaDIbI4NaaaAehNk92OsY82E=; b=C5QzKXZBcf3oks+Hm3wJIxkJ9NyrCOedExyQcMRI9SD9dqPPj/DOoPSwu70SzHtETQ xbW/IRt5pI0xB4XD5iq/de+Uz6AunQsSsxJIeBLy8nBsJLrO43MtZghXuj1qo9tXGqTi eTOipoNwPEyDc7d4tMGejsVSM+lPP0ntbFYvQJJW3lqhXDY3HaB8w9mBsRd7lZISDtmj /Dd5soKH2blQsoD/D8yLxAw2fB9QIZ/PMhVUd6/xZK9EC8d4lleLZZCEX6bGHT76xRi4 +xhOFqqKtQfzsVyyhY11SDAsXdPzjnl3lo5Yrzsin60Q+eiYyWZ7wNMo8MhWN6mKkOEm B/xw== X-Gm-Message-State: AOAM533uhT8YgkX6tMbFXiCFgt+93cQ3hKzBhm5gpAZ7fWK7J5mgl4J3 j4WLrTU9wa0oOfyN0e3wV+T6OURwHujaLA== X-Google-Smtp-Source: ABdhPJx8t/zX+LsPuUGtzoQPRetlZo0iJLdvdxZFJoF5oJi4GPh9kgbHEYWBwFV+DfQMAn47CrifyA== X-Received: by 2002:a1c:a916:: with SMTP id s22mr8390852wme.82.1617285397828; Thu, 01 Apr 2021 06:56:37 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n7sm10145770wrv.71.2021.04.01.06.56.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Apr 2021 06:56:37 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Olga Telezhnaya , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 5/5] ref-filter: fix NULL check for parse object failure Date: Thu, 1 Apr 2021 15:56:30 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.474.g72d45d12706 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Jeff King After we run parse_object_buffer() to get an object's contents, we try to check that the return value wasn't NULL. However, since our "struct object" is a pointer-to-pointer, and we assign like: *obj = parse_object_buffer(...); it's not correct to check: if (!obj) That will always be true, since our double pointer will continue to point to the single pointer (which is itself NULL). This is a regression that was introduced by aa46a0da30 (ref-filter: use oid_object_info() to get object, 2018-07-17); since that commit we'll segfault on a parse failure, as we try to look at the NULL object pointer. There are many ways a parse could fail, but most of them are hard to set up in the tests (it's easy to make a bogus object, but update-ref will refuse to point to it). A minimal stand-alone test can be found at, but let's use the newly amended t3800-mktag.sh tests to test these cases exhaustively on all sorts of bad tags. 1. http://lore.kernel.org/git/YGWFGMdGcKeaqCQF@coredump.intra.peff.net Signed-off-by: Jeff King Signed-off-by: Ævar Arnfjörð Bjarmason --- ref-filter.c | 2 +- t/t3800-mktag.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ref-filter.c b/ref-filter.c index f0bd32f7141..a0adb4551d8 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1608,7 +1608,7 @@ static int get_object(struct ref_array_item *ref, int deref, struct object **obj if (oi->info.contentp) { *obj = parse_object_buffer(the_repository, &oi->oid, oi->type, oi->size, oi->content, &eaten); - if (!obj) { + if (!*obj) { if (!eaten) free(oi->content); return strbuf_addf_ret(err, -1, _("parse_object_buffer failed on %s for %s"), diff --git a/t/t3800-mktag.sh b/t/t3800-mktag.sh index 10e4fde28de..b175d639013 100755 --- a/t/t3800-mktag.sh +++ b/t/t3800-mktag.sh @@ -64,7 +64,7 @@ check_verify_failure () { git -C bad-tag for-each-ref "$tag_ref" >actual && test_cmp expected actual && # segfaults! - ! git -C bad-tag for-each-ref --format="%(*objectname)" + test_must_fail git -C bad-tag for-each-ref --format="%(*objectname)" ' }