From patchwork Mon Jun 21 15:03:37 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: 12334949 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,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 47484C48BC2 for ; Mon, 21 Jun 2021 15:03:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2762361151 for ; Mon, 21 Jun 2021 15:03:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230059AbhFUPGA (ORCPT ); Mon, 21 Jun 2021 11:06:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229887AbhFUPF5 (ORCPT ); Mon, 21 Jun 2021 11:05:57 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D36E1C061756 for ; Mon, 21 Jun 2021 08:03:42 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id c84so10717895wme.5 for ; Mon, 21 Jun 2021 08:03:42 -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=UzaEbYpDgAe2DKw3PX2eCQh16rWu6u4aMso01MeMx18=; b=sMgnghqhc0vN/Ggb7H73NszhMIZshDFOK2sLDoMjznb2FewOmR60W6IThrRNnu1gJg mOy+ipGUMgyOREv63wkpz3FlS/dWYxHc37IsRjEgq4w+tSwjLEaoCGRUa028eiNsSdGz 18QMdIosTqp3KaA0T2hroMiuFNPiqarSWQETB8HASsnq9wVlaR7bEsZDeAjmGgzKtz7t I8v7WWQrxYkchq/Rt9ItnjA+PUShcpkSKndDFRVMrKfApWUYSpY6jmvEUn+DYX+x0q4r 8bnPODevzi7A5ndcdUEAi70NWGsfAKQPsmufcTFjE9tI/nrPcNh/vu9R4sCDEtxp44NJ ZaqQ== 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=UzaEbYpDgAe2DKw3PX2eCQh16rWu6u4aMso01MeMx18=; b=jFkqnkkqoiB54M1ed2Zk+gg+r78kG+DFHKBpZRYYQxthokuV76pn96zeX6Wp21SFs+ UrvP8WdJXgTVe/Xo5E/TUI+1YganZBLYBfU7tZSvN2dW96QMEq+dSR9XoMDrIIqOS8KO 0jxPi07NlV9H1lCWC+snZEBPmsLv0PzAF1CKbSQR+6PXOuP3kpDCSr+fBG/6Lwd5PJOT g5iDUWHZRTv7knojSnPafaQAYlOEAZRCVX6xsnRhwHooehMTya7Ue7hZx61Al+JnSy8D hADEhxmOayJQkOoy5jATtZOBIGFSjo8utYVKga5M56CLVBPRttq4OrgnxMANPWGGLdU+ QTFw== X-Gm-Message-State: AOAM531QMG8Y8ntz41haynLDan0DPf1zsNOtnRwJaP32GQvSpcekCrVQ 5lsn+oOgu50zwbmJKl5tu3kwWyygrMTnMw== X-Google-Smtp-Source: ABdhPJz3EQBiH+meG+9LNzlFgsI7JneC+CVObY1Psi5/vuuL/qbyW06/cHgzWk72u2O3FZmVXTKdzg== X-Received: by 2002:a7b:c410:: with SMTP id k16mr631092wmi.28.1624287821220; Mon, 21 Jun 2021 08:03:41 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id y4sm11931939wrw.71.2021.06.21.08.03.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Jun 2021 08:03:40 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Taylor Blau , Jeff King , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 1/2] pack-objects tests: cover blindspots in stdin handling Date: Mon, 21 Jun 2021 17:03:37 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.599.g3967b4fa4ac In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Cover blindspots in the testing of stdin handling, including the "!len" condition added in b5d97e6b0a0 (pack-objects: run rev-list equivalent internally., 2006-09-04). The codepath taken with --revs and read_object_list_from_stdin() acts differently in some of these common cases, let's test for those. The "--stdin --revs" test being added here stresses the combination of --stdin-packs and the revision.c --stdin argument, some of this was covered in a test added in 339bce27f4f (builtin/pack-objects.c: add '--stdin-packs' option, 2021-02-22), but let's make sure that GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=true keeps erroring out about --stdin, and it isn't picked up by the revision.c API's handling of that option. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t5300-pack-object.sh | 85 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh index 5c5e53f0be9..65e991e3706 100755 --- a/t/t5300-pack-object.sh +++ b/t/t5300-pack-object.sh @@ -34,6 +34,91 @@ test_expect_success 'setup' ' } >expect ' +test_expect_success 'setup pack-object in <<-EOF && + $(git -C pack-object-stdin rev-parse one) + EOF + + git -C pack-object-stdin pack-objects basic-stdin actual && + test_line_count = 1 actual && + + git -C pack-object-stdin pack-objects --revs basic-stdin-revs actual && + test_line_count = 3 actual +' + +test_expect_success 'pack-object in <<-EOF && + $(git -C pack-object-stdin rev-parse one) + garbage + $(git -C pack-object-stdin rev-parse two) + EOF + + sed "s/^> //g" >err.expect <<-EOF && + fatal: expected object ID, got garbage: + > garbage + + EOF + test_must_fail git -C pack-object-stdin pack-objects bad-line-stdin err.actual && + test_cmp err.expect err.actual && + + cat >err.expect <<-EOF && + fatal: bad revision '"'"'garbage'"'"' + EOF + test_must_fail git -C pack-object-stdin pack-objects --revs bad-line-stdin-revs err.actual && + test_cmp err.expect err.actual +' + +test_expect_success 'pack-object in <<-EOF && + $(git -C pack-object-stdin rev-parse one) + + $(git -C pack-object-stdin rev-parse two) + EOF + + sed -e "s/^> //g" -e "s/Z$//g" >err.expect <<-EOF && + fatal: expected object ID, got garbage: + > Z + + EOF + test_must_fail git -C pack-object-stdin pack-objects empty-line-stdin err.actual && + test_cmp err.expect err.actual && + + git -C pack-object-stdin pack-objects --revs empty-line-stdin-revs actual && + test_line_count = 3 actual +' + +test_expect_success 'pack-object in <<-EOF && + $(git -C pack-object-stdin rev-parse one) + $(git -C pack-object-stdin rev-parse two) + EOF + + # There is the "--stdin-packs is incompatible with --revs" + # test below, but we should make sure that the revision.c + # --stdin is not picked up + cat >err.expect <<-EOF && + fatal: disallowed abbreviated or ambiguous option '"'"'stdin'"'"' + EOF + test_must_fail git -C pack-object-stdin pack-objects stdin-with-stdin-option --stdin err.actual && + test_cmp err.expect err.actual && + + test_must_fail git -C pack-object-stdin pack-objects --stdin --revs stdin-with-stdin-option-revs 2>err.actual # e.g.: check_deltas stderr -gt 0 check_deltas() { From patchwork Mon Jun 21 15:03:38 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: 12334951 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,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 249C8C49EA2 for ; Mon, 21 Jun 2021 15:03:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0382D61001 for ; Mon, 21 Jun 2021 15:03:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230082AbhFUPGB (ORCPT ); Mon, 21 Jun 2021 11:06:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229904AbhFUPF6 (ORCPT ); Mon, 21 Jun 2021 11:05:58 -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 9971DC06175F for ; Mon, 21 Jun 2021 08:03:43 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id h21-20020a1ccc150000b02901d4d33c5ca0so203680wmb.3 for ; Mon, 21 Jun 2021 08:03:43 -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=wvmOoU+qw5MfjxE3Ker/KbH+PChm0hEdKygxZukDSv8=; b=AD6N0kZKNbjUx+Ktgiz0OAM1HVa28dxxOhpDkrJdigtTQizkZSQtno5fzf7w1BAS77 U1G7lKxAzvde0F4O23JngpZc1XA2pU2xG9UFAp1H3suoQYkQ83s6BN8l6SnPuNJo3xeW lDK/Mu5ko+nBm6s6nHbc97ObhVHVGy7hWdPA9rteJceHSd6eY18azyIw9+/penonEBzH SvOgYDuTseYEdILa+0UqDWqdZJp+BwcGw3P4G1Uw2guwD4Y0KdM3JHtCnRHW5hkTNEsx 1U9tGDFyCn8hKWQjEAXnpVN+rSKPzP1GZ2Do9QWvG2ABcd5ueSB+dCBWeNi/WWuwFfJ8 tZCA== 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=wvmOoU+qw5MfjxE3Ker/KbH+PChm0hEdKygxZukDSv8=; b=o1/gI4CXzR2IuUXyNlwLiN/zbsDLCnjnwSSKXgjGXK38j+N1lUfe8/bT7VdzVxYNVR OK79emhhF62vA4MQOKPuv22umOIl0oOH7eozu4g9o9UjLf3zKCZnGTKG2uv+N5eMcyXQ cFQMR2Lwf7ZYzDDFP+d9xybejUcrdTCqq9z660ABX0jRV4apGyXFvPRpyUxeUU6B905o F/Z+mmGLSUC2nPufrmeBXVehcpFHreNqFbsa2jJMBz+TkrBqV3r6dIeNNsWWHu6ooKmB uG8l/Y7cGTPaMdwMlsUllD7aEJQBWEWjKw+yllD3oAG7zS9W1lD3B7xnkAHKKR+ou0vQ 3SMw== X-Gm-Message-State: AOAM531iG2A/BTZHXtC1WVhOtD2m9TuNAfYX974nrYJyvwF5EG7+I/fs MHBrAyMHiWLAGnaYQFsPw923dXqsKlULxw== X-Google-Smtp-Source: ABdhPJxhoy4IhwCyeXTCsNBXF5qSTTiXebGiXnIIpOZdkPVeotQ1o7tcFy6kkbDhQxMShcLyN6O76w== X-Received: by 2002:a7b:c149:: with SMTP id z9mr16073184wmi.77.1624287821990; Mon, 21 Jun 2021 08:03:41 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id y4sm11931939wrw.71.2021.06.21.08.03.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Jun 2021 08:03:41 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Taylor Blau , Jeff King , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 2/2] pack-objects: fix segfault in --stdin-packs option Date: Mon, 21 Jun 2021 17:03:38 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.599.g3967b4fa4ac In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a segfault in the --stdin-packs option added in 339bce27f4f (builtin/pack-objects.c: add '--stdin-packs' option, 2021-02-22). The read_packs_list_from_stdin() function didn't check that the lines it was reading were valid packs, and thus when doing the QSORT() with pack_mtime_cmp() we'd have a NULL "util" field. The logic error was in assuming that we could iterate all packs and annotate the excluded and included packs we got, as opposed to checking the lines we got on stdin. There was a check for excluded packs, but included packs were simply assumed to be valid. As noted in the test we'll not report the first bad line, but whatever line sorted first according to the string-list.c API. In this case I think that's fine. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/pack-objects.c | 10 ++++++++++ t/t5300-pack-object.sh | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index de00adbb9e0..65579e09fe0 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -3310,6 +3310,16 @@ static void read_packs_list_from_stdin(void) item->util = p; } + /* + * Arguments we got on stdin may not even be packs. Check that + * to avoid segfaulting later on in e.g. pack_mtime_cmp(). + */ + for_each_string_list_item(item, &include_packs) { + struct packed_git *p = item->util; + if (!p) + die(_("could not find pack '%s'"), item->string); + } + /* * First handle all of the excluded packs, marking them as kept in-core * so that later calls to add_object_entry() discards any objects that diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh index 65e991e3706..330deec656b 100755 --- a/t/t5300-pack-object.sh +++ b/t/t5300-pack-object.sh @@ -119,6 +119,24 @@ test_expect_success 'pack-object in <<-EOF && + $(git -C pack-object-stdin rev-parse one) + $(git -C pack-object-stdin rev-parse two) + EOF + + # We actually just report the first bad line in strcmp() + # order, it just so happens that we get the same result under + # SHA-1 and SHA-256 here. It does not really matter that we + # report the first bad item in this obscure case, so this + # oddity of the test is OK. + cat >err.expect <<-EOF && + fatal: could not find pack '"'"'$(git -C pack-object-stdin rev-parse two)'"'"' + EOF + test_must_fail git -C pack-object-stdin pack-objects stdin-with-stdin-option --stdin-packs err.actual && + test_cmp err.expect err.actual +' + # usage: check_deltas # e.g.: check_deltas stderr -gt 0 check_deltas() {