From patchwork Thu Apr 21 20:14:34 2022 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: 12822358 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD127C433FE for ; Thu, 21 Apr 2022 20:14:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1392259AbiDUURf (ORCPT ); Thu, 21 Apr 2022 16:17:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1392289AbiDUURd (ORCPT ); Thu, 21 Apr 2022 16:17:33 -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 5629A3ED04 for ; Thu, 21 Apr 2022 13:14:42 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id bv16so8143822wrb.9 for ; Thu, 21 Apr 2022 13:14:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vGTBEKBV6o8C90oxiV5WDqxa80vdz5MKTnYUG/Y7cXA=; b=YmrmMroWO0fBlpbJWTGpJ3HimzgotBR12YpoIxLhO1qdw4ziJGsS7hUfh5fsMA/Usj vhahyTgXdJTZO5L1FQYZhPsnhU5dJS30iIQD1G72tIjqwYhzcEfKnGpiBX240jpccqdL oP2qRMgmH7hySu9PwXI5+loiTz8NGWRAf7Q48oA1TRe5KWBWMEVq/eKaSGt3ZTaYyslK rrPgbNp9RUK6aa3CF8wnpT6w1f4kvrYOwA3kLH0BGWKq9X7gIOKGYTGB+En1p46PJvCw W+drxHj+sEsFz8T/1Ept/bPcI3+QIU2Swo7lMbxF7kmZhzJtsj2Pc93FY35xQAYChO5P qUmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vGTBEKBV6o8C90oxiV5WDqxa80vdz5MKTnYUG/Y7cXA=; b=bnKoESwdaC/pmGMWORNytRNiJDw84RyUXESjUg1Uy1LmOVL34ZOn3rZ5Ld6RHlHIpD KjxBZU+EJBhEaYEyIzLVSmUBKaPKAVhQRKd4kC4XTCns6FeIeAtj65UfzTegPLO89Wx1 CoAZE24E7AIZTd5wJjzAwDs/m0ZQzL/7p3GJqjDoxoGHyDDTIgjj23YYzlVhL4tCh7JV Xh3MV406WyWd+G15CRDQb0IvG0jEPXWWKlJ57qme2JPalBwtcM/z4BAjWISbphlSHlJR 8FIgQ8tJWJzR9N3y7pIqaXJLSd7DnXvkPr6n0iWS3bjaNpXNpFWLZAwe4UXcmvgUbfYl bVSw== X-Gm-Message-State: AOAM532cuCjnRRyIFLuo/Pd5od0fg4E4A8k4cf9IsX7yO7BOo2LiOuCA 00hs4eEABUG2oqtDV1e62ASdhioinrDHVA== X-Google-Smtp-Source: ABdhPJySm786BKN2o4Ur9iIZnqexdk2yVAPpLuQeMkgyeRWwIe6Ip5b716ODX5VX6fbpEYuooQN7lA== X-Received: by 2002:a05:6000:1686:b0:20a:96e0:9bbe with SMTP id y6-20020a056000168600b0020a96e09bbemr959185wrd.635.1650572080571; Thu, 21 Apr 2022 13:14:40 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l9-20020a1c7909000000b0038eb8171fa5sm1309wme.1.2022.04.21.13.14.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Apr 2022 13:14:40 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Johannes Schindelin , Hans Jerry Illikainen , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH 1/4] tests: make RUNTIME_PREFIX compatible with --valgrind Date: Thu, 21 Apr 2022 22:14:34 +0200 Message-Id: X-Mailer: git-send-email 2.36.0.879.gd068ac2c328 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a regression in b7d11a0f5d2 (tests: exercise the RUNTIME_PREFIX feature, 2021-07-24) where tests that want to set up and test a "git" wrapper in $PATH conflicted with the t/bin/valgrind wrapper(s) doing the same. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t0060-path-utils.sh | 4 ++-- t/test-lib.sh | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index 2fe6ae6a4e5..aa35350b6f3 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -542,7 +542,7 @@ test_lazy_prereq CAN_EXEC_IN_PWD ' ./git rev-parse ' -test_expect_success RUNTIME_PREFIX,CAN_EXEC_IN_PWD 'RUNTIME_PREFIX works' ' +test_expect_success !VALGRIND,RUNTIME_PREFIX,CAN_EXEC_IN_PWD 'RUNTIME_PREFIX works' ' mkdir -p pretend/bin pretend/libexec/git-core && echo "echo HERE" | write_script pretend/libexec/git-core/git-here && cp "$GIT_EXEC_PATH"/git$X pretend/bin/ && @@ -550,7 +550,7 @@ test_expect_success RUNTIME_PREFIX,CAN_EXEC_IN_PWD 'RUNTIME_PREFIX works' ' echo HERE >expect && test_cmp expect actual' -test_expect_success RUNTIME_PREFIX,CAN_EXEC_IN_PWD '%(prefix)/ works' ' +test_expect_success !VALGRIND,RUNTIME_PREFIX,CAN_EXEC_IN_PWD '%(prefix)/ works' ' mkdir -p pretend/bin && cp "$GIT_EXEC_PATH"/git$X pretend/bin/ && git config yes.path "%(prefix)/yes" && diff --git a/t/test-lib.sh b/t/test-lib.sh index 531cef097db..7f3d323e937 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -1666,6 +1666,7 @@ test -n "$USE_LIBPCRE2" && test_set_prereq PCRE test -n "$USE_LIBPCRE2" && test_set_prereq LIBPCRE2 test -z "$NO_GETTEXT" && test_set_prereq GETTEXT test -n "$SANITIZE_LEAK" && test_set_prereq SANITIZE_LEAK +test -n "$GIT_VALGRIND_ENABLED" && test_set_prereq VALGRIND if test -z "$GIT_TEST_CHECK_CACHE_TREE" then From patchwork Thu Apr 21 20:14:35 2022 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: 12822359 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7BB2C433F5 for ; Thu, 21 Apr 2022 20:14:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1392268AbiDUURj (ORCPT ); Thu, 21 Apr 2022 16:17:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1392298AbiDUURd (ORCPT ); Thu, 21 Apr 2022 16:17:33 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B93163C8 for ; Thu, 21 Apr 2022 13:14:43 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id m14so8182334wrb.6 for ; Thu, 21 Apr 2022 13:14:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8biSKho1+OKVOIB8CCTd48exGbAiqISG8dmbrNrlW+E=; b=YC0eLDCwL+kPb2m54F3/vYG2lTT7VPzFZKy/DtHxtC1ylnbHibJAhFAQy3BnwX7X7l 43ZKGAu4z+azw+1v13nqsdDXpOVLK+mpD97UEUCI6NJtV2w+UBXYXv/qVhXPwVvpJBvP OeQvTemMYFZuelm29e97j7lkZiMYnjLbBTqQGtKD5t0DGEiM6Q80VRn2gQbUq0R4GU3c /j0Ae1WCre5r1n2vnuxBJVI4ihaifr9XzuSTzeMzDuvgcATbor9QpUIuaJJU1s+56WbI xFSN+bsW0FDmNNm7ucCS8Mx7RGuiZ3KEsHXBkwgYsY6h1B5tkImB5/0z/Ci0hCMwXrgD IqCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8biSKho1+OKVOIB8CCTd48exGbAiqISG8dmbrNrlW+E=; b=zM7PfRmiqyeuY1k2HJ2iNHXgoNEVJYy4VZlYsmLNqlQZkbL23NHbq3NcC7Fdyu54Ny f3qJj0lR7PcSepSqrXg3cX5o8BvOhq5aPYHuoowO6oukl1ZUep1GZGOb8QXi6P9wkYLU OuyfADZoNbr59PVOeEz89FaqMi/GMMDiXVZbD8yIkMECC0KHpuNtRBtXYxf8bt9ZH352 7oVQ7Xskk3C6s24pVBAiIbCUcwMvaUOIKp02M6bTJ2we3xU53EXBzX6KSV36plXVq0IG vpbK+nDNcoHWOaQhbrrc3Sjc/K2qTqAi4pJ0Bg5uxuGT7AjJWFYfQJNMdKKAUdBu6nQO 1Yww== X-Gm-Message-State: AOAM531FzZCU2RnlSNLzr3MI5E4jfKtSmpOpejb6uIhs3ZMsNBCPGNcD MjieYyOT7Etxd81iWB4+CUqvGQZqXv7Png== X-Google-Smtp-Source: ABdhPJxUExWP8Tx3yJrTYpvRnGxo6v1txXAQy2xQa9VAyhN8gbO74ZLjUqMj3apcgOWjW7n3jyl5kw== X-Received: by 2002:adf:d1cb:0:b0:20a:880b:13d2 with SMTP id b11-20020adfd1cb000000b0020a880b13d2mr1005386wrd.323.1650572081518; Thu, 21 Apr 2022 13:14:41 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l9-20020a1c7909000000b0038eb8171fa5sm1309wme.1.2022.04.21.13.14.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Apr 2022 13:14:40 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Johannes Schindelin , Hans Jerry Illikainen , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH 2/4] log test: skip a failing mkstemp() test under valgrind Date: Thu, 21 Apr 2022 22:14:35 +0200 Message-Id: X-Mailer: git-send-email 2.36.0.879.gd068ac2c328 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Skip a test added in f1e3df31699 (t: increase test coverage of signature verification output, 2020-03-04) when running under valgrind. Due to valgrind's interception of mkstemp() this test will fail with: + pwd + TMPDIR=[...]/t/trash directory.t4202-log/bogus git log --show-signature -n1 plain-fail ==7696== VG_(mkstemp): failed to create temp file: [...]/t/trash directory.t4202-log/bogus/valgrind_proc_7696_cmdline_d545ddcf [... 10 more similar lines omitted ..] valgrind: Startup or configuration error: valgrind: Can't create client cmdline file in [...]/t/trash directory.t4202-log/bogus/valgrind_proc_7696_cmdline_6e542d1d valgrind: Unable to start up properly. Giving up. error: last command exited with $?=1 Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t4202-log.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/t/t4202-log.sh b/t/t4202-log.sh index be07407f855..6e663525582 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -1992,10 +1992,13 @@ test_expect_success GPG 'log --show-signature for merged tag with GPG failure' ' git tag -s -m signed_tag_msg signed_tag_fail && git checkout plain-fail && git merge --no-ff -m msg signed_tag_fail && - TMPDIR="$(pwd)/bogus" git log --show-signature -n1 plain-fail >actual && - grep "^merged tag" actual && - grep "^No signature" actual && - ! grep "^gpg: Signature made" actual + if ! test_have_prereq VALGRIND + then + TMPDIR="$(pwd)/bogus" git log --show-signature -n1 plain-fail >actual && + grep "^merged tag" actual && + grep "^No signature" actual && + ! grep "^gpg: Signature made" actual + fi ' test_expect_success GPGSM 'log --graph --show-signature for merged tag x509' ' From patchwork Thu Apr 21 20:14:36 2022 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: 12822360 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 928C0C433EF for ; Thu, 21 Apr 2022 20:14:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1392269AbiDUURk (ORCPT ); Thu, 21 Apr 2022 16:17:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1392258AbiDUURe (ORCPT ); Thu, 21 Apr 2022 16:17:34 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF27E3ED04 for ; Thu, 21 Apr 2022 13:14:43 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id ay11-20020a05600c1e0b00b0038eb92fa965so6599491wmb.4 for ; Thu, 21 Apr 2022 13:14:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1cj3i3A0VAQpHlvrWYX1jw1uy5JzgitcbZw9J8lE3LM=; b=BQlDlodP7mTqc0Sf4hgLOmczK7a9sqCn7gqRNf7mKgfIE8IaRqYHoz7rsUSCrgKt0u hvJBBXjIo5Gp0CP2d6dCHcA4BqYT7v7pTxEMA3C5H33BobQQz8FhGofOo94Fpy0JQCTi 1H9yiVkdyD+xLbnidkq7XHN6v2tpfXKhsQT8pRDAF0gF2f2ImyvDXLLwi73kwCoUY/Gl G1G4EToujqhpTSBmFBuQwOrtIDmrRA87F7u3qtuQRAVwVt8PCW4/gF3rQIs7s0ml5AWC FXA3cm5WXk2QPa31aYyr0bpp4oT3RjpZk6crpxyOiqZ7zfYIfrvilp9eWge0zeBCcBqt 0Uiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1cj3i3A0VAQpHlvrWYX1jw1uy5JzgitcbZw9J8lE3LM=; b=6I5+vePDsKSg77aAHR0VZmwjQUQxJc9RfQtw5ZEGkhFtLJS1bLPwcg3RDg4/omA9Ex ffQZt5N1zxmyGU3ZP53fu8MlasNV1LfLGuf4pLYl6NIkI4y0TI5Yj4hOLps3w8KD7NXg 14Ex/YV7uRuecFZGfsPoynSlSl25IS4GnttrCKJwKchCXg1Ou7V7TXwHK8zGFA5kNxPx nlP9JYi8ge6dEoLza9fxYkjG4M6Y4gwe3hnI0wtVf+6Vmdp3u0eoqjf4h8XVuCFZBrhp Qr70B/4hqELCVuMUOVUUbrN2a7773MwsxqrQsCsiPLbEr9yZGel+nIa6D7Bo3NtH3sXw 6IRA== X-Gm-Message-State: AOAM53256vpqiw7zpMscu7PyzWte9dokOlxjLGHHvB/Bm5klAis+yfUM nDp+P5qC8QNaVxxOhgswbMEIYKAPxs2CEA== X-Google-Smtp-Source: ABdhPJyzTIvGBoUCwxw/2TRjEBkIaBc8cFoecQpyvVzFMVGPf/1tPhnAm215ZWwmXkJ3i7YFP4jmKw== X-Received: by 2002:a05:600c:4e01:b0:392:ab42:48 with SMTP id b1-20020a05600c4e0100b00392ab420048mr899136wmq.169.1650572082278; Thu, 21 Apr 2022 13:14:42 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l9-20020a1c7909000000b0038eb8171fa5sm1309wme.1.2022.04.21.13.14.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Apr 2022 13:14:41 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Johannes Schindelin , Hans Jerry Illikainen , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH 3/4] commit-graph.c: don't assume that stat() succeeds Date: Thu, 21 Apr 2022 22:14:36 +0200 Message-Id: X-Mailer: git-send-email 2.36.0.879.gd068ac2c328 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix code added in 8d84097f965 (commit-graph: expire commit-graph files, 2019-06-18) to check the return value of the stat() system call. Not doing so caused us to use uninitialized memory in the "Bloom generation is limited by --max-new-filters" test in t4216-log-bloom.sh: + rm -f trace.event + pwd + GIT_TRACE2_EVENT=[...]/t/trash directory.t4216-log-bloom/limits/trace.event git commit-graph write --reachable --split=replace --changed-paths --max-new-filters=2 ==24835== Syscall param utimensat(times[0].tv_sec) points to uninitialised byte(s) ==24835== at 0x499E65A: __utimensat64_helper (utimensat.c:34) ==24835== by 0x4999142: utime (utime.c:36) ==24835== by 0x552BE0: mark_commit_graphs (commit-graph.c:2213) ==24835== by 0x550822: write_commit_graph (commit-graph.c:2424) ==24835== by 0x54E3A0: write_commit_graph_reachable (commit-graph.c:1681) ==24835== by 0x4374BB: graph_write (commit-graph.c:269) ==24835== by 0x436F7D: cmd_commit_graph (commit-graph.c:326) ==24835== by 0x407B9A: run_builtin (git.c:465) ==24835== by 0x406651: handle_builtin (git.c:719) ==24835== by 0x407575: run_argv (git.c:786) ==24835== by 0x406410: cmd_main (git.c:917) ==24835== by 0x511F09: main (common-main.c:56) ==24835== Address 0x1ffeffde70 is on thread 1's stack ==24835== in frame #1, created by utime (utime.c:25) ==24835== Uninitialised value was created by a stack allocation ==24835== at 0x552B50: mark_commit_graphs (commit-graph.c:2201) ==24835== [...] error: last command exited with $?=126 not ok 137 - Bloom generation is limited by --max-new-filters This would happen as we stat'd the non-existing ".git/objects/info/commit-graph" file. Let's fix mark_commit_graphs() to check the statu() return value, and while we're at it fix another case added in the same commit to do the same. The caller in expire_commit_graphs() would have been less likely to run into this, as it's operating on files it just got from readdir(), but it could still happen due to a race with e.g. a concurrent "rm -rf" of the commit-graph files. Signed-off-by: Ævar Arnfjörð Bjarmason --- commit-graph.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/commit-graph.c b/commit-graph.c index 441b36016ba..2b528187316 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -2206,7 +2206,8 @@ static void mark_commit_graphs(struct write_commit_graph_context *ctx) struct stat st; struct utimbuf updated_time; - stat(ctx->commit_graph_filenames_before[i], &st); + if (stat(ctx->commit_graph_filenames_before[i], &st) < 0) + continue; updated_time.actime = st.st_atime; updated_time.modtime = now; @@ -2247,7 +2248,8 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx) strbuf_setlen(&path, dirnamelen); strbuf_addstr(&path, de->d_name); - stat(path.buf, &st); + if (stat(path.buf, &st) < 0) + continue; if (st.st_mtime > expire_time) continue; From patchwork Thu Apr 21 20:14:37 2022 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: 12822361 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB513C433EF for ; Thu, 21 Apr 2022 20:14:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1392272AbiDUURl (ORCPT ); Thu, 21 Apr 2022 16:17:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1392262AbiDUURf (ORCPT ); Thu, 21 Apr 2022 16:17:35 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCCA463C8 for ; Thu, 21 Apr 2022 13:14:44 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id c10so8200159wrb.1 for ; Thu, 21 Apr 2022 13:14:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0rykYwV184Lwzck3W+SVmZMd3E4Ln/SjrwPXsvi9smg=; b=co2tJFCY1EmKbM3Tc1n0T4oJjXI7VyGBfIt5WzN4fVyfS/9KLFTWifiMkAFDm+1IXb sFKeiQYV67WqtG8JA9T0W98wuTZKY2YU1CkxbCCl+Mhr4pobSPhfknHx/EwO4dp+6Fbv p2T8uL8dYTpvQP32BKG5GQogGh890kEzWIjdH9/xdCHseLDE3zl98LPIo1z8DmwqK/WO BD0hvGSTdI1JFeQg9a89mgehnwpojIqute8EwCBPvI3ZMfUNEcTC+GECAZjR+KccS5OP h6pMkHFr6Z4AxSHntppcSpCmt+ytLMNyfbwDiDhd9mWVJuGjAU3BlvybdN80YuhnmTmu 7DRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0rykYwV184Lwzck3W+SVmZMd3E4Ln/SjrwPXsvi9smg=; b=iDs3pVJr42RPmKkNkvLPVBYNbj47hxaFH9SB8kmSoyMBN+z7VA5kXsqUW1BzzCOhY4 5ZpKtJdzOjWBxP+AeTzlCKd2aWeZNCQiWuyXbyvyVbyEfaBGis4Lfh4vAhjkjlt9cjb3 JHio+LMbCaJPWCfW4D5T7wNS2NdK9r6N6iE3AjJjN9cCoUgCxXLO7FS9rzqBfYDhsc5F eoA+UToNdUm2GIHkE6qopPiFbrr1iNDWhHmBlafCgQBlWda30bUFP8te4T+OPvi/1rdQ 5D/5zx8PfxwCMlb00OFW31v88+euSGmL/90afIBJzsFeNjT+iNukpj6vrNatKrc+/LYB nWbQ== X-Gm-Message-State: AOAM531In5xYUjxDFDr5tRtGG2k6k878ZqAKxClUWcFgsjsJoMOtpFNr kHw06aYAzRHP3SlAj4cjX2fQV/1Acb/80Q== X-Google-Smtp-Source: ABdhPJwaagArTRJGfqgMYcF+MK6qb4w3+fhLn+8xn/GGvu1iVMQGPZ/GkZVa7bhWn+wDBL6g5AqJuw== X-Received: by 2002:a5d:6d50:0:b0:207:c10e:911 with SMTP id k16-20020a5d6d50000000b00207c10e0911mr1002383wri.137.1650572083122; Thu, 21 Apr 2022 13:14:43 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l9-20020a1c7909000000b0038eb8171fa5sm1309wme.1.2022.04.21.13.14.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Apr 2022 13:14:42 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Johannes Schindelin , Hans Jerry Illikainen , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH 4/4] object-file: fix a unpack_loose_header() regression in 3b6a8db3b03 Date: Thu, 21 Apr 2022 22:14:37 +0200 Message-Id: X-Mailer: git-send-email 2.36.0.879.gd068ac2c328 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a regression in my 3b6a8db3b03 (object-file.c: use "enum" return type for unpack_loose_header(), 2021-10-01) revealed both by running the test suite with --valgrind, and with the amended "git fsck" test. In practice this regression in v2.34.0 caused us to claim that we couldn't parse the header, as opposed to not being able to unpack it. Before the change in the C code the test_cmp added here would emit: -error: unable to unpack header of ./objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 +error: unable to parse header of ./objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 I.e. we'd proceed to call parse_loose_header() on the uninitialized "hdr" value, and it would have been very unlikely for that uninitialized memory to be a valid git object. The other callers of unpack_loose_header() were already checking the enum values exhaustively. See 3b6a8db3b03 and 5848fb11acd (object-file.c: return ULHR_TOO_LONG on "header too long", 2021-10-01). Signed-off-by: Ævar Arnfjörð Bjarmason --- object-file.c | 8 ++++++-- t/t1006-cat-file.sh | 10 ++++++++-- t/t1450-fsck.sh | 13 +++++++++++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/object-file.c b/object-file.c index 5ffbf3d4fd4..b5d1d12b68a 100644 --- a/object-file.c +++ b/object-file.c @@ -2623,8 +2623,12 @@ int read_loose_object(const char *path, goto out; } - if (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr), - NULL) < 0) { + switch (unpack_loose_header(&stream, map, mapsize, hdr, sizeof(hdr), + NULL)) { + case ULHR_OK: + break; + case ULHR_BAD: + case ULHR_TOO_LONG: error(_("unable to unpack header of %s"), path); goto out; } diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh index 1b852076944..dadf3b14583 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -681,7 +681,7 @@ test_expect_success 'cat-file -t and -s on corrupt loose object' ' # Setup and create the empty blob and its path empty_path=$(git rev-parse --git-path objects/$(test_oid_to_path "$EMPTY_BLOB")) && - git hash-object -w --stdin other.blob && @@ -722,7 +722,13 @@ test_expect_success 'cat-file -t and -s on corrupt loose object' ' # content out as-is. Try to make it zlib-invalid. mv -f other.blob "$empty_path" && test_must_fail git fsck 2>err.fsck && - grep "^error: inflate: data stream error (" err.fsck + cat >expect <<-EOF && + error: inflate: data stream error (incorrect header check) + error: unable to unpack header of ./$empty_path + error: $empty_blob: object corrupt or missing: ./$empty_path + EOF + grep "^error: " err.fsck >actual && + test_cmp expect actual ) ' diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index de50c0ea018..ab7f31f1dcd 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -774,10 +774,19 @@ test_expect_success 'fsck finds problems in duplicate loose objects' ' # no "-d" here, so we end up with duplicates git repack && # now corrupt the loose copy - file=$(sha1_file "$(git rev-parse HEAD)") && + oid="$(git rev-parse HEAD)" && + file=$(sha1_file "$oid") && rm "$file" && echo broken >"$file" && - test_must_fail git fsck + test_must_fail git fsck 2>err && + + cat >expect <<-EOF && + error: inflate: data stream error (incorrect header check) + error: unable to unpack header of $file + error: $oid: object corrupt or missing: $file + EOF + grep "^error: " err >actual && + test_cmp expect actual ) '