From patchwork Mon May 20 20:22:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13668638 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B8FF9137C48 for ; Mon, 20 May 2024 20:22:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716236533; cv=none; b=iHnCymj+sXk/xrBehpDKNhUmxZOiWbGG/wsbachW6vQaavHMWw0snG7Dp1ObddAm3fIoqeeEAZKqzOghWfPvttDTtfpzStvAvkNhCn8Hkx2DC9lSweh17gTP3iQBXKkEHHGjAeyuu7/BGWHQeNcey8jtCxdn8AlSkYke6Flx1ps= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716236533; c=relaxed/simple; bh=eomBttJUDugeAh4/E/RHJ5Kl046QR71tdtyo18mV/ck=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=P+1FX7LwQdDiSig28gEiv+/exIUZdUBWnC+CItIZ9APaPoB+qTo+536hcTI6YEFdI8TP4BFIUjF/V0Bu4Eurjir32TLOMuh0D+bjugh3wbnll+ZmgNiwi5yOt+ionN89pt3rZKh/SdrIgYVTu+WTqG63+iQacZn3Ui1R2KsHC4I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hwV4MozY; arc=none smtp.client-ip=209.85.221.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hwV4MozY" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-351da5838fcso2810023f8f.1 for ; Mon, 20 May 2024 13:22:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716236530; x=1716841330; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=Pa4ywTRMbTP0sOgRCz5rqk9gwHUD4hcDu9QhBPTQQ6M=; b=hwV4MozYzj68WmswCojsUwVPqojixexgCx06HBsW8nYXpM+POy8q8istnCnN0uI2E7 P5Gbupg2GAuuJ6u8oUWdJGvHAaUXu9p1ouimgm3+4B+hofXr+RKjO979SCV9PLJSMIea StQnaJWrE9iiJ6TGVnPmUJwIi7oLE45/vhGN91Z0Px0sme2B8+Uq5RInuO0awM/DgHCT EltmSQhS+2Le7cb0aG23N8seMTvzomJBAoZlyosnBX3nJZWIG6b0Hnblab4jJMO1ZyYp 0tSHcA4O77DDocy7B9lRw5elG11KVe3DyQRtIvhHHr4Bnyl94MYoN0Q1VXPbn2CbdfXX iXtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716236530; x=1716841330; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Pa4ywTRMbTP0sOgRCz5rqk9gwHUD4hcDu9QhBPTQQ6M=; b=FBZk3nfyGl2rVJyVqcVZhIFppfBRogcvaIm9Po5wY48hpLs41hWCJcv5DmdRHFMYcD W6EHkH88PAUBpswgEaThgKiDGPQMVsnNx8oeKnyg9HJNRAfq8pdoQ/U7Dvx08lx7reEY PEDeVYdot01JrYF7s8xk9/hVvLpeOkQYfHZVvPnJdXqgkXo4VhdKNVal2aZOj9g40JZk HVEr8G9fI3ptwqaNzraME+N/+dZuqJmLC4Bdmv70UjENj94I5XPvYzcLeQOzwS9psFRl c3R2tfxAoAOZELSSlI1Z4clZyMKxuKO0oB+Vs2VLeWriJWZWeLuOKAZ5LMuAuFhLTB+q XCUQ== X-Gm-Message-State: AOJu0YzDQLxFEr+rGcEFmzBcEE3qzQbKL31YJmvauGpGHb8iskR5gXWg f/9cEoBixmJbbDOv4JjS/9n9h3mm6Ds8Is4I89h+f+br9HIpumZIo+k8pg== X-Google-Smtp-Source: AGHT+IGHlJd+NeSuUTXknGCPrloMiobEYLj8ygnpnWIOCj6195u+gfAC5+ebhjPgh/G0Fd6ffmcGfQ== X-Received: by 2002:a05:6000:114c:b0:34d:a9:6642 with SMTP id ffacd0b85a97d-3504a73821emr23497791f8f.28.1716236529604; Mon, 20 May 2024 13:22:09 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3525f7f7d88sm10651425f8f.57.2024.05.20.13.22.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 13:22:09 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 20 May 2024 20:22:00 +0000 Subject: [PATCH v3 1/6] hook: plug a new memory leak Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: "brian m. carlson" , Jeff King , Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin In 8db1e8743c0 (clone: prevent hooks from running during a clone, 2024-03-28), I introduced an inadvertent memory leak that was unfortunately not caught before v2.45.1 was released. Here is a fix. Signed-off-by: Johannes Schindelin --- hook.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hook.c b/hook.c index 632b537b993..fc974cee1d8 100644 --- a/hook.c +++ b/hook.c @@ -18,8 +18,10 @@ static int identical_to_template_hook(const char *name, const char *path) found_template_hook = access(template_path.buf, X_OK) >= 0; } #endif - if (!found_template_hook) + if (!found_template_hook) { + strbuf_release(&template_path); return 0; + } ret = do_files_match(template_path.buf, path); From patchwork Mon May 20 20:22:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13668640 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6DAB137C55 for ; Mon, 20 May 2024 20:22:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716236534; cv=none; b=JHRT8ELNUf23xuk14aqpHy1uHlKxH4azcpq7QP7G+U6SIWedLm3+Wqx+DmGuLZ4g8tSBEEHXTLCwrpoBXPYlRpMoa3cKrjbv1b5ErjTvdTJipviYIFnxLaCsP9lXV9Ql8ildDvlexofPoHVZD5S2IlsawHH5Mp1Xp00hYlfrR2w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716236534; c=relaxed/simple; bh=g3mcr9oNJA2YWVKdqdh6JD9CfQ682VkR8dwEEitGi70=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=X8b7tPKotY7SOxnjXtNg52N56T9AVqVLNBJXTYHyUn+AdaeEv3UrNNphlVWe29Ewwp1IfnXWBOloElQGX6mpVyB13Zog3w/0S76tSQWlWQudacF28yVzJeiF6uaRh3Ozqkc/oyntt837XpG7gx5YfoVlwu3Bvc3rphYEuubqlHs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ToQb/fuI; arc=none smtp.client-ip=209.85.221.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ToQb/fuI" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-34dc129accaso2381828f8f.0 for ; Mon, 20 May 2024 13:22:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716236531; x=1716841331; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=p3TcY6SNGMN9D4Tqo4JhzJB1VLG5CDwDx+Tm37TVHyE=; b=ToQb/fuI2CsTXnYwiF15U7p1qoGE7ZYoHHz6UUZkw6/vUaL5Ou6Bouu3w3O86MYXVu w2ThAnBetSGVzC8xvFvX/R+dvlNKY4wfkg3un/K+e0PAsnbuJY/MnT2hCMcp4gkaVSgH uYkgcQzUSok9dayKf2VrM0yN4JgVaQ+JZTinl/gcN4KAnGf8h00BTIFZylwzuklrLq+0 NvBTk2cYvoXtbzvgW32J1LNyDaIx7fp00VabziyOy8yRiZspqXL6PEvUsbbZHXV3cOsg NeH4DShb6lmjczVfCaKbm/XQWN812WqpU1sOjwLf1jOproI61/C5BpZoyD9jq7NILk6D awPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716236531; x=1716841331; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=p3TcY6SNGMN9D4Tqo4JhzJB1VLG5CDwDx+Tm37TVHyE=; b=ubCcvT+gApyNnAsEGEMEAazmbTnWK7V2y7V51/OmXC5UHHvVZIoYYK4xsQvU7t4PB0 B4pzf0VS8GlVVBbHR7JyRnMcbgRazdAzjxEyaqUnNLar1MDjibhXtijf1daXZGe3+ZPg AJnC+GikB1Z/srw5UkZu+3bOWFuk89B/h5jCTSWAOpLnkpP840F3UQKKG5MPKm25GL1G 19coa74T3/AIgZYf1vXPFM1AvGJRiJClLRMIfzFnkKNP3qZuNPeZynnoNvYrybNNYqA/ 60e840MrneS672gvk3xrPm/h5jBdRPhOnB/NfrjgBZrrxeSuA9BKGkmSPkvQ76iEpfn2 Zd2Q== X-Gm-Message-State: AOJu0YxKlY+n9QTxI/gOEJrR7W04ejnZKtD6+gStYrWRV0oBzQ2u5eiK l6nKw87Wi7LMJ/6TLGf1VeEbwAJFA7WA/RcvcMFwJC6QCjspH/Vd4yo9EA== X-Google-Smtp-Source: AGHT+IElSFlZDF7szQVcGWliButOO7e8P+7xNRe5hQcNS2ZAlLfITOfK45gyaldPINPep70TbUn/ZA== X-Received: by 2002:a5d:53c5:0:b0:349:fc93:1dc with SMTP id ffacd0b85a97d-3504a632dcamr21586598f8f.8.1716236530842; Mon, 20 May 2024 13:22:10 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3502baacfb9sm29813499f8f.68.2024.05.20.13.22.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 13:22:09 -0700 (PDT) Message-Id: <961dfc35f426388d660cca4e92f43e169819886a.1716236526.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 20 May 2024 20:22:01 +0000 Subject: [PATCH v3 2/6] init: use the correct path of the templates directory again Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: "brian m. carlson" , Jeff King , Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin In df93e407f06 (init: refactor the template directory discovery into its own function, 2024-03-29), I refactored the way the templates directory is discovered. The refactoring was faithful, but missed a reference in the `Makefile` where the `DEFAULT_GIT_TEMPLATE_DIR` constant is defined. As a consequence, Git v2.45.1 and friends will always use the hard-coded path `/usr/share/git-core/templates`. Let's fix that by defining the `DEFAULT_GIT_TEMPLATE_DIR` when building `setup.o`, where that constant is actually used. Signed-off-by: Johannes Schindelin --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 093829ae283..4b1502ba2c6 100644 --- a/Makefile +++ b/Makefile @@ -2751,7 +2751,7 @@ exec-cmd.sp exec-cmd.s exec-cmd.o: EXTRA_CPPFLAGS = \ '-DFALLBACK_RUNTIME_PREFIX="$(prefix_SQ)"' builtin/init-db.sp builtin/init-db.s builtin/init-db.o: GIT-PREFIX -builtin/init-db.sp builtin/init-db.s builtin/init-db.o: EXTRA_CPPFLAGS = \ +setup.sp setup.s setup.o: EXTRA_CPPFLAGS = \ -DDEFAULT_GIT_TEMPLATE_DIR='"$(template_dir_SQ)"' config.sp config.s config.o: GIT-PREFIX From patchwork Mon May 20 20:22:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13668641 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E7A0139578 for ; Mon, 20 May 2024 20:22:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716236535; cv=none; b=j8toV056B78OfI4knLjZ/UZV3xFlE+2JOm3w9LwE0cmXVVYLHfj3N0/LZSdZJ8o9EgIb+fB6BQ+B8sQZyc0sUZKmUGOWXKuHT6uw6+5xR67cY+chnXPFYRfas3ixkL+YYt9GA6SYx71wWnA93zLNRU6Toq8zwLnLFAqPT7fUf6Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716236535; c=relaxed/simple; bh=NACUjCKOyFbBT9Jcvg+gdcvRvWOxx7KfWVnfiD/FlN4=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=iR6HmlJuzAzNyeDNUB9O6X7mOqo+2YSFhNttPtOsKSFq/XD+fv6ZO/BLXlMcnqW8hbegLrjbpjzcQTTFKlCy3X1e2BkFFGUYJp+NqAk4mfTBJfiXtasohvz/cjvc91+8tLti8cGwd2b58G44eHSf0vdlal37ycC0YOQHJ0OCEEk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZiaiSGmR; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZiaiSGmR" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-420180b5838so18200925e9.2 for ; Mon, 20 May 2024 13:22:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716236532; x=1716841332; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=i6d3NikhGkK867apaAyTM/p8Uvw8q8n1MJ0T9cVpYng=; b=ZiaiSGmRIES36sHw7+8fuoKd8+xRH5YzhKs5QlXswL70dYpZ6LlXkd32Ea9HDhrOWC a1lpuFyAskZCZ78hDsAfa2ksS4Awc5Hn2eLt9It2uaAY2mGrxaHUGnsDlVo7ttwGon36 xkRNgSHYal/hR+WS8rwdssn/naERc7QeTWUOQKGOaNI6bW7zDe2K0pjCBrT8z/z14va9 xkPKOKCKAq1r0jKb8qr9n6c5kDCDJhiq7ZA//qoFIyzyGV93szwlAccA0MJAPIGbbeuX o6+wQo1VElwWE5GRMp3Zf9DTvSq9cWw2xm6q4Y21nADRfFGo0jHlhmRZtrtABXUPvPOX ogkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716236532; x=1716841332; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i6d3NikhGkK867apaAyTM/p8Uvw8q8n1MJ0T9cVpYng=; b=ehlV6PIuwAs/P5JOiYO1jpwFgUEKmGz3kIrpG+76PQEb8dLjaV/acJsebaR6wvLK1l whM/Uvk/nQ/kWTbqeaOnAJKp0Fc4Tcj0dBB04iljmz+KEvDWJ7a8zsnK/mvW9IwhBUNt KlvJtkHnNi8Tz7Lnyag5+qifzeSImrkX7lMoJlac+9i4nU1BaG19PT376MMCQJS2kUJF KRIwIZlMYRWcriANj+qkkwLRFwqERfZdUvfuFgCmNGgDja4IudwT+6SjcmjkIqycvIM8 yfC7NYyB/HqBnzVSYe1WaBtDR/WCdDiGweEPQNF/3cqWrP81xDUq7yDpqk7ood0nxzPY t7KQ== X-Gm-Message-State: AOJu0YzLrPpJ4qvcK6vjvK9U1FzbNzYba29zywmyau1mzy301hQHSKDR bgWpQbgOgD9X1hJtisTGZ84RqHi5F55yqs8TCaWVfsaqzSKX81rtohnc8w== X-Google-Smtp-Source: AGHT+IERd8BUQHHQjfWCaHwegdX9ASxC5fX1vn0k8gEuqH/WeKKUICUILA0oe8ymqPsBtFkPf4B5Dg== X-Received: by 2002:a05:600c:4614:b0:415:6daf:c626 with SMTP id 5b1f17b1804b1-41feaa4392amr294540965e9.21.1716236531817; Mon, 20 May 2024 13:22:11 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4201da9895csm277442365e9.44.2024.05.20.13.22.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 13:22:11 -0700 (PDT) Message-Id: <57db89a14977bdff01f8f82cb4d6f85cc49d4b55.1716236526.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 20 May 2024 20:22:02 +0000 Subject: [PATCH v3 3/6] Revert "core.hooksPath: add some protection while cloning" Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: "brian m. carlson" , Jeff King , Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin This defense-in-depth was intended to protect the clone operation against future escalations where bugs in `git clone` would allow attackers to write arbitrary files in the `.git/` directory would allow for Remote Code Execution attacks via maliciously-placed hooks. However, it turns out that the `core.hooksPath` protection has unintentional side effects so severe that they do not justify the benefit of the protections. For example, it has been reported in https://lore.kernel.org/git/FAFA34CB-9732-4A0A-87FB-BDB272E6AEE8@alchemists.io/ that the following invocation, which is intended to make `git clone` safer, is itself broken by that protective measure: git clone --config core.hooksPath=/dev/null Since it turns out that the benefit does not justify the cost, let's revert 20f3588efc6 (core.hooksPath: add some protection while cloning, 2024-03-30). Signed-off-by: Johannes Schindelin --- config.c | 13 +------------ t/t1800-hook.sh | 15 --------------- 2 files changed, 1 insertion(+), 27 deletions(-) diff --git a/config.c b/config.c index 85b37f2ee09..8c1c4071f0d 100644 --- a/config.c +++ b/config.c @@ -1525,19 +1525,8 @@ static int git_default_core_config(const char *var, const char *value, void *cb) if (!strcmp(var, "core.attributesfile")) return git_config_pathname(&git_attributes_file, var, value); - if (!strcmp(var, "core.hookspath")) { - if (current_config_scope() == CONFIG_SCOPE_LOCAL && - git_env_bool("GIT_CLONE_PROTECTION_ACTIVE", 0)) - die(_("active `core.hooksPath` found in the local " - "repository config:\n\t%s\nFor security " - "reasons, this is disallowed by default.\nIf " - "this is intentional and the hook should " - "actually be run, please\nrun the command " - "again with " - "`GIT_CLONE_PROTECTION_ACTIVE=false`"), - value); + if (!strcmp(var, "core.hookspath")) return git_config_pathname(&git_hooks_path, var, value); - } if (!strcmp(var, "core.bare")) { is_bare_repository_cfg = git_config_bool(var, value); diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh index 7ee12e6f48a..2ef3579fa7c 100755 --- a/t/t1800-hook.sh +++ b/t/t1800-hook.sh @@ -177,19 +177,4 @@ test_expect_success 'git hook run a hook with a bad shebang' ' test_cmp expect actual ' -test_expect_success 'clone protections' ' - test_config core.hooksPath "$(pwd)/my-hooks" && - mkdir -p my-hooks && - write_script my-hooks/test-hook <<-\EOF && - echo Hook ran $1 - EOF - - git hook run test-hook 2>err && - grep "Hook ran" err && - test_must_fail env GIT_CLONE_PROTECTION_ACTIVE=true \ - git hook run test-hook 2>err && - grep "active .core.hooksPath" err && - ! grep "Hook ran" err -' - test_done From patchwork Mon May 20 20:22:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13668642 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78567139581 for ; Mon, 20 May 2024 20:22:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716236536; cv=none; b=Id9l0GMNFN9/6X2X/h5Pogk//C2V9wbz86RyQZ7/EH2yy8z5nE3V8sFZgOY9do2qOrekCegvwqH3bfDNwJ0CqEBocmXxciWvXioIU20sPVAdSsc+5Njuo41B5MaxQHVhCOqvo1HOoOXFHbe0j4g8x1m2coKRH9VSt5xt1cu5GLg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716236536; c=relaxed/simple; bh=9GRY60ElemT9DHs8npnd8hLlNR8z3x1QzrFwTtQ6KpE=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=QGzeAeqJHrMMaNDWv2loBMNAcRHaGcEhxKLTXKTB5AwwdMwfXLvY3fW+yWYbYWt74zZQgOyjx0aeQW2UFwnD/pXzGZBpw6RpX/Sh5qg4gXbSXTpRfStxCe0LhWTxR+RjW9lXmM6dRjXdl3acocZFZN0JWURtLIg1vZBTGAT8TkE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bbLwqKS3; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bbLwqKS3" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4202ca70270so33847865e9.3 for ; Mon, 20 May 2024 13:22:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716236532; x=1716841332; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=8Hh0zgo3PA9OZD3gGP/KbTGUs6ILXCU7En0Epx60GCc=; b=bbLwqKS3s1DO7PqVZcV6ILuR+F5uGfTVnLdMUJ9Lmn0UFzUPun5W9JvV0PtKqdb4Xd FLwKBmfhuqsNtZSEXDGQouDQZKmo+s2o5qCs61LEAOwqR9NE/h+tZ2x+bkrNIaJqCrVz P0dHG3uWqitCIPN574iUtz/9ABkfPz/1aWe99tBtODg55DRekZtWE9KOENktKIXO0aL1 otmTN4MoFMV3m4VHLQB4jNLZxCa/HxQQaTaqiwKzbjifuXvKwuPTqcfqzYmJ/9L7d2iN P7hX4GkgH2KFPb5XNi3GonoP+g+sOA9ADhwAwm9aDBVUSVsTMDioRKPTQHasYHQhuHlO qmHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716236532; x=1716841332; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8Hh0zgo3PA9OZD3gGP/KbTGUs6ILXCU7En0Epx60GCc=; b=TwWOVN54Q8z0xPnfXlewqXwl52stNPv3vVflW7Eqqon6GvndZXaYGEIXtwJXDb4coF u0xwplxL4Er8yo93Y/dNKxjUZPaYER/on3sfQImjk53Bc029q/ViaboZ3CaU9Uc4GFeh vt0dyZcDCyfbqIDy2nVKYrFIdvwWuTmX2Lf3sNrYrwuEo3EXbspyW5JRBjhc8auDtfxY 8i6OEUyUZaN/bz99rqqjM5Nlss7byJ4HMo5Rw1PZyT3fBtr7GhzOjhaAMuVtFk7CLhDz VQDHcMiPv2kQbGAqKB3D8SnG+QvSjXc4vD8UfsYLRi270u4CMuReOhqeDh9mVtek1VQw lYRA== X-Gm-Message-State: AOJu0Yx2vaTNvmb9yW36j9RWqZDIJiGYSnNS0p9gGNGDhqz3jzvgxODv YFlfa4xRFNeWT8B5rLqki0cxiWNc1XVX5vtvfwwLTJeLgUz9APHxX7B5+A== X-Google-Smtp-Source: AGHT+IFuofaJrwXZMOI09X/eB2mGNS8YIDXNn/ODv/kJeOy9GeAcwAJCSVCFdQ7wSLV8qxWV9SWwlw== X-Received: by 2002:a05:600c:5116:b0:41b:fa34:9e48 with SMTP id 5b1f17b1804b1-41feac55e26mr293670415e9.30.1716236532414; Mon, 20 May 2024 13:22:12 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-41fccbe8fa6sm434956365e9.2.2024.05.20.13.22.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 13:22:12 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Mon, 20 May 2024 20:22:03 +0000 Subject: [PATCH v3 4/6] tests: verify that `clone -c core.hooksPath=/dev/null` works again Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: "brian m. carlson" , Jeff King , Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin As part of the protections added in Git v2.45.1 and friends, repository-local `core.hooksPath` settings are no longer allowed, as a defense-in-depth mechanism to prevent future Git vulnerabilities to raise to critical level if those vulnerabilities inadvertently allow the repository-local config to be written. What the added protection did not anticipate is that such a repository-local `core.hooksPath` can not only be used to point to maliciously-placed scripts in the current worktree, but also to _prevent_ hooks from being called altogether. We just reverted the `core.hooksPath` protections, based on the Git maintainer's recommendation in https://lore.kernel.org/git/xmqq4jaxvm8z.fsf@gitster.g/ to address this concern as well as related ones. Let's make sure that we won't regress while trying to protect the clone operation further. Reported-by: Brooke Kuhlmann Signed-off-by: Johannes Schindelin --- t/t1350-config-hooks-path.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/t/t1350-config-hooks-path.sh b/t/t1350-config-hooks-path.sh index f6dc83e2aab..45a04929170 100755 --- a/t/t1350-config-hooks-path.sh +++ b/t/t1350-config-hooks-path.sh @@ -41,4 +41,11 @@ test_expect_success 'git rev-parse --git-path hooks' ' test .git/custom-hooks/abc = "$(cat actual)" ' +test_expect_success 'core.hooksPath=/dev/null' ' + git clone -c core.hooksPath=/dev/null . no-templates && + value="$(git -C no-templates config --local core.hooksPath)" && + # The Bash used by Git for Windows rewrites `/dev/null` to `nul` + { test /dev/null = "$value" || test nul = "$value"; } +' + test_done From patchwork Mon May 20 20:22:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13668643 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1ABB13959D for ; Mon, 20 May 2024 20:22:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716236537; cv=none; b=dT0+tP/pg2YtF6hmDAkV5EufoJlMbZFTv//EaXcuVuLhRkRrGgaGKBmgIwsXPsg+yjZnkaDb4Vhmpfyt3YxJHduq3mKWIPSltg4Eg2gjjSOvSX0viTZvWanISEhFbA1WwRCYWU0k4b2BCLxcWtnVfET8FwW7yZy/4HyjBf+OOgo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716236537; c=relaxed/simple; bh=lVlVuRjx8gjlzFTetk5MCJ3bUQmhiKmjB3YGwzs6oaQ=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=HAnkFsb/G/M8cWIbIVyORG5nRam2cUX/nmPYPQ58CrwH6a5FmEwvqx3Yd0Y45XnPkr1Fl5lBxrKxlpYlGyNpyGHt7xEARsabKxt/IYfEuS6Z2M8npby+8UcqadSmPUEgm/EJEyA4M91J2Tg+N8MI+NX4kmutQeyBPIFNW0Fk3+k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ExGR99EM; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ExGR99EM" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-42016c8db2aso24591275e9.0 for ; Mon, 20 May 2024 13:22:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716236533; x=1716841333; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=wxtT5xN3WXiWC4lzK+9yatqNRwvBZc6woP7q6d5Fgzk=; b=ExGR99EMUOXnAj0ufThOa0rbmHkwAZydXyYkNA5qV7gJNo0goUVb2y/LNZ8It/12EK BDjoJyWZekZ7Ihd4mRWJvlapVunDZZhk9iMCKd70nt+gQWlyPKEn9ikl6jAgF3i4NgYu hg2pw1/zwAzjq7/pQuXMJqVifp0trfV/RGWVZWDDvwLELzkVDs2+5G76sVXo8zt7waFv c4LaW9UzhY9R4ZgDR/o0836EG6CPs0tNJBOpe077M+fPxpj0OL7zHrY1Y4X9JipvVUeM Q2sEpTJcVze62QLsiVlOXZtwZlf6S8wfB3RKJCVV2VRlO357MoOt7XlW5ArYnpFvpqjO 7kMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716236533; x=1716841333; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wxtT5xN3WXiWC4lzK+9yatqNRwvBZc6woP7q6d5Fgzk=; b=AMLB5SEzaLP4ln5xUXqb10qxFM5ANOQ1yTbsFw0+ccjradKXTcExYUNf0YkdQuXd+3 0jxMurWDMEkGWthUyvP4R2QbsAmgM2OagqsRUlNdMB3fiXRwLRl37EYr+uLJo9BA6pyW RFEUBS0JST9jlxuUkNeUezclGeDswsR/obA8i303FbLO3Z8momyReNaX4o2r2P1ANW5k NDuvZEbB28EB4k+isBMuzBn4CFaXunynQxz4SWbroq+FiE30zr85aCzBrsGA8OH6BIBO 75qxT0ZPsTqsMdQ3Qw6vx1QsS1qxS0M4yFh8arinzgN9T0l+i4H0tuMQZHYmXyuAsXPV gLMg== X-Gm-Message-State: AOJu0YwF5pnQ2jZcQowWASTkoXj77wjjYvclShZ4tvF0NaagdHrcMcTg SlM+f3Yh3pn4uzCRsqy56K753IP+BbDVGMlOFC62tc6vIu6EZqcljiaMPw== X-Google-Smtp-Source: AGHT+IGy/7sstPQWijPOB1lpCgu7A0gIiaI4VCfh7W0vPMXR3QuXPYrAD6QkZjBT5O0nncu706uDIQ== X-Received: by 2002:a05:600c:1e15:b0:420:2986:cce1 with SMTP id 5b1f17b1804b1-4202986d034mr103296165e9.32.1716236533553; Mon, 20 May 2024 13:22:13 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-41fccee9292sm435399695e9.37.2024.05.20.13.22.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 13:22:12 -0700 (PDT) Message-Id: <0044a35567417a552cc518576670b43f7141a02e.1716236526.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 20 May 2024 20:22:04 +0000 Subject: [PATCH v3 5/6] clone: drop the protections where hooks aren't run Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: "brian m. carlson" , Jeff King , Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin As part of the security bug-fix releases v2.39.4, ..., v2.45.1, I introduced logic to safeguard `git clone` from running hooks that were installed _during_ the clone operation. The rationale was that Git's CVE-2024-32002, CVE-2021-21300, CVE-2019-1354, CVE-2019-1353, CVE-2019-1352, and CVE-2019-1349 should have been low-severity vulnerabilities but were elevated to critical/high severity by the attack vector that allows a weakness where files inside `.git/` can be inadvertently written during a `git clone` to escalate to a Remote Code Execution attack by virtue of installing a malicious `post-checkout` hook that Git will then run at the end of the operation without giving the user a chance to see what code is executed. Unfortunately, Git LFS uses a similar strategy to install its own `post-checkout` hook during a `git clone`; In fact, Git LFS is installing four separate hooks while running the `smudge` filter. While this pattern is probably in want of being improved by introducing better support in Git for Git LFS and other tools wishing to register hooks to be run at various stages of Git's commands, let's undo the clone protections to unbreak Git LFS-enabled clones. This reverts commit 8db1e8743c0 (clone: prevent hooks from running during a clone, 2024-03-28). Signed-off-by: Johannes Schindelin --- builtin/clone.c | 12 +----------- hook.c | 34 -------------------------------- t/t5601-clone.sh | 51 ------------------------------------------------ 3 files changed, 1 insertion(+), 96 deletions(-) diff --git a/builtin/clone.c b/builtin/clone.c index e7721f5c22c..9ec500d427e 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -937,8 +937,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix) int err = 0, complete_refs_before_fetch = 1; int submodule_progress; int filter_submodules = 0; - const char *template_dir; - char *template_dir_dup = NULL; struct transport_ls_refs_options transport_ls_refs_options = TRANSPORT_LS_REFS_OPTIONS_INIT; @@ -958,13 +956,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix) usage_msg_opt(_("You must specify a repository to clone."), builtin_clone_usage, builtin_clone_options); - xsetenv("GIT_CLONE_PROTECTION_ACTIVE", "true", 0 /* allow user override */); - template_dir = get_template_dir(option_template); - if (*template_dir && !is_absolute_path(template_dir)) - template_dir = template_dir_dup = - absolute_pathdup(template_dir); - xsetenv("GIT_CLONE_TEMPLATE_DIR", template_dir, 1); - if (option_depth || option_since || option_not.nr) deepen = 1; if (option_single_branch == -1) @@ -1112,7 +1103,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) } } - init_db(git_dir, real_git_dir, template_dir, GIT_HASH_UNKNOWN, NULL, + init_db(git_dir, real_git_dir, option_template, GIT_HASH_UNKNOWN, NULL, INIT_DB_QUIET); if (real_git_dir) { @@ -1430,7 +1421,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix) free(unborn_head); free(dir); free(path); - free(template_dir_dup); UNLEAK(repo); junk_mode = JUNK_LEAVE_ALL; diff --git a/hook.c b/hook.c index fc974cee1d8..22b274b60b1 100644 --- a/hook.c +++ b/hook.c @@ -3,32 +3,6 @@ #include "run-command.h" #include "config.h" -static int identical_to_template_hook(const char *name, const char *path) -{ - const char *env = getenv("GIT_CLONE_TEMPLATE_DIR"); - const char *template_dir = get_template_dir(env && *env ? env : NULL); - struct strbuf template_path = STRBUF_INIT; - int found_template_hook, ret; - - strbuf_addf(&template_path, "%s/hooks/%s", template_dir, name); - found_template_hook = access(template_path.buf, X_OK) >= 0; -#ifdef STRIP_EXTENSION - if (!found_template_hook) { - strbuf_addstr(&template_path, STRIP_EXTENSION); - found_template_hook = access(template_path.buf, X_OK) >= 0; - } -#endif - if (!found_template_hook) { - strbuf_release(&template_path); - return 0; - } - - ret = do_files_match(template_path.buf, path); - - strbuf_release(&template_path); - return ret; -} - const char *find_hook(const char *name) { static struct strbuf path = STRBUF_INIT; @@ -64,14 +38,6 @@ const char *find_hook(const char *name) } return NULL; } - if (!git_hooks_path && git_env_bool("GIT_CLONE_PROTECTION_ACTIVE", 0) && - !identical_to_template_hook(name, path.buf)) - die(_("active `%s` hook found during `git clone`:\n\t%s\n" - "For security reasons, this is disallowed by default.\n" - "If this is intentional and the hook should actually " - "be run, please\nrun the command again with " - "`GIT_CLONE_PROTECTION_ACTIVE=false`"), - name, path.buf); return path.buf; } diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index 20deca0231b..fd029843307 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -771,57 +771,6 @@ test_expect_success 'batch missing blob request does not inadvertently try to fe git clone --filter=blob:limit=0 "file://$(pwd)/server" client ' -test_expect_success 'clone with init.templatedir runs hooks' ' - git init tmpl/hooks && - write_script tmpl/hooks/post-checkout <<-EOF && - echo HOOK-RUN >&2 - echo I was here >hook.run - EOF - git -C tmpl/hooks add . && - test_tick && - git -C tmpl/hooks commit -m post-checkout && - - test_when_finished "git config --global --unset init.templateDir || :" && - test_when_finished "git config --unset init.templateDir || :" && - ( - sane_unset GIT_TEMPLATE_DIR && - NO_SET_GIT_TEMPLATE_DIR=t && - export NO_SET_GIT_TEMPLATE_DIR && - - git -c core.hooksPath="$(pwd)/tmpl/hooks" \ - clone tmpl/hooks hook-run-hookspath 2>err && - ! grep "active .* hook found" err && - test_path_is_file hook-run-hookspath/hook.run && - - git -c init.templateDir="$(pwd)/tmpl" \ - clone tmpl/hooks hook-run-config 2>err && - ! grep "active .* hook found" err && - test_path_is_file hook-run-config/hook.run && - - git clone --template=tmpl tmpl/hooks hook-run-option 2>err && - ! grep "active .* hook found" err && - test_path_is_file hook-run-option/hook.run && - - git config --global init.templateDir "$(pwd)/tmpl" && - git clone tmpl/hooks hook-run-global-config 2>err && - git config --global --unset init.templateDir && - ! grep "active .* hook found" err && - test_path_is_file hook-run-global-config/hook.run && - - # clone ignores local `init.templateDir`; need to create - # a new repository because we deleted `.git/` in the - # `setup` test case above - git init local-clone && - cd local-clone && - - git config init.templateDir "$(pwd)/../tmpl" && - git clone ../tmpl/hooks hook-run-local-config 2>err && - git config --unset init.templateDir && - ! grep "active .* hook found" err && - test_path_is_missing hook-run-local-config/hook.run - ) -' - . "$TEST_DIRECTORY"/lib-httpd.sh start_httpd From patchwork Mon May 20 20:22:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13668644 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 95A3D139CEB for ; Mon, 20 May 2024 20:22:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716236538; cv=none; b=IhfH38umyoEqcsT8Asdmy+d9QJDdY96SxBYe9ENyXLV1IxLwsGle2VqjV3l+/QX0fHE8Mkt7mKq6Px5bnvBTUoTZdfg/pqVpMcgZG7J7V34Qxz3deT7PZsAs/YHEX9jSWQukq5sfGiA5fCQQM5FfPFKmXVVPgO2Tv7G8a5se810= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716236538; c=relaxed/simple; bh=ldVou3LjvRyszwlkSq0AhyfPkMxbgdNiKzyu2EBNRqU=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=FQrhCwBMS7nvBvxfbafuDB347dUr+wqa626C4enHT0qVqdpSw9lw6VuZOpBCtnZLzd7sl0S1PuUcQfQdg85tjxEfp/tvVsF0815+eFWWCkt0a3Qk443aVSjzIb5jx5SLtSwNXgAo6ycVJbLLMY4QRK006RgVClsm7F3LZcUql0Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dDq0lp8S; arc=none smtp.client-ip=209.85.221.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dDq0lp8S" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-34dc8d3fbf1so2068215f8f.1 for ; Mon, 20 May 2024 13:22:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716236534; x=1716841334; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=Zrr1+lMEsbdxBYmZl3ymH80XsSKj7Aucdz/ecD0EJAM=; b=dDq0lp8SOQEVKXlRMxWog0tTddaHE15USyg9SaFO3VT/me+3uGQx33St4t8j63HsTF HIk/An7wjJzr1onm/JS21lcyG92BCNDtJq6f/RnUpRtfDi8AeCrVxJmWI0Y0+atVz2pu 43X6K/jTGO2Hs+xRWeyBYtKG8KB+C2xfKoM80kSU82QcIgC3L9zw6FBrlEpOgDzm+vQn PgeHa9Crl/OaZm1lLqrtQuo8X5taA0gL0yg+10frRqi5CkxXSpcqBv5lAR9yefJoduY2 5wwe4JlNBsw1lNsEL+cAjswKLEKdA3A70QjvPAHk/dLzvZvlHu8s1rwQMLqYyG/+qxIg KGuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716236534; x=1716841334; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Zrr1+lMEsbdxBYmZl3ymH80XsSKj7Aucdz/ecD0EJAM=; b=c5Jj9E4nvwkOtz8AD2u72/dTiN2ef49I1jJNybA71cEt55RvtknieMd7O7A7Rp9cdS 0gcucHqWrRx2Fh3Fb7PY5zmQLtIxyWHv3MhRi4d2c4ZH/AYK8oITAz07okW9ObMtS2gy Qj+9ON5Q4QDrYuA77L90XIbWGt6PepiBUZ2uF6eq/u1InJNvlv+8NqdN+R0n6jiYKupw NE3JyIKOCW8NRvW/X5/MW27Y9csALjp8YyghWlNNLFQN9eu6eRN+yiWLFSStY4BdpN7V iOIi1SPbUTg99mxzoSME4++ahyvSOCuN/K7r2i/aC/Mmljjb0WgkssN5nEojM2juW2fa iqMg== X-Gm-Message-State: AOJu0YzJOWkSWwsp6/8NaUyADVzw2/P3UCyLMqpSNrBJFFS7eJN+n/um xF+Jw/EQwwDlQRs78AsGKGI7oLZvJETPOsw+W6Hwa02M59rYNrUYUJhc5A== X-Google-Smtp-Source: AGHT+IEEbXw4gHO6iGGo0lSfFCs06OMZoe0swFd5V4C2ctf9+IlryZL1uEF8ji0s4F6ef3VwGGIxSQ== X-Received: by 2002:adf:c047:0:b0:351:c731:ed0b with SMTP id ffacd0b85a97d-351c731eec5mr11646173f8f.70.1716236534624; Mon, 20 May 2024 13:22:14 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3502b79bc83sm29950250f8f.16.2024.05.20.13.22.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 13:22:14 -0700 (PDT) Message-Id: <5c576e889d85b34fc717b693ba526cc46836f66a.1716236527.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 20 May 2024 20:22:05 +0000 Subject: [PATCH v3 6/6] Revert "Add a helper function to compare file contents" Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: "brian m. carlson" , Jeff King , Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin Now that during a `git clone`, the hooks' contents are no longer compared to the templates' files', the caller for which the `do_files_match()` function was introduced is gone, and therefore this function can be retired, too. This reverts commit 584de0b4c23 (Add a helper function to compare file contents, 2024-03-30). Signed-off-by: Johannes Schindelin --- cache.h | 14 --------- copy.c | 58 -------------------------------------- t/helper/test-path-utils.c | 10 ------- t/t0060-path-utils.sh | 41 --------------------------- 4 files changed, 123 deletions(-) diff --git a/cache.h b/cache.h index 16b34799bfd..8c5fb1e1ba1 100644 --- a/cache.h +++ b/cache.h @@ -1785,20 +1785,6 @@ int copy_fd(int ifd, int ofd); int copy_file(const char *dst, const char *src, int mode); int copy_file_with_time(const char *dst, const char *src, int mode); -/* - * Compare the file mode and contents of two given files. - * - * If both files are actually symbolic links, the function returns 1 if the link - * targets are identical or 0 if they are not. - * - * If any of the two files cannot be accessed or in case of read failures, this - * function returns 0. - * - * If the file modes and contents are identical, the function returns 1, - * otherwise it returns 0. - */ -int do_files_match(const char *path1, const char *path2); - void write_or_die(int fd, const void *buf, size_t count); void fsync_or_die(int fd, const char *); int fsync_component(enum fsync_component component, int fd); diff --git a/copy.c b/copy.c index 8492f6fc831..4de6a110f09 100644 --- a/copy.c +++ b/copy.c @@ -65,61 +65,3 @@ int copy_file_with_time(const char *dst, const char *src, int mode) return copy_times(dst, src); return status; } - -static int do_symlinks_match(const char *path1, const char *path2) -{ - struct strbuf buf1 = STRBUF_INIT, buf2 = STRBUF_INIT; - int ret = 0; - - if (!strbuf_readlink(&buf1, path1, 0) && - !strbuf_readlink(&buf2, path2, 0)) - ret = !strcmp(buf1.buf, buf2.buf); - - strbuf_release(&buf1); - strbuf_release(&buf2); - return ret; -} - -int do_files_match(const char *path1, const char *path2) -{ - struct stat st1, st2; - int fd1 = -1, fd2 = -1, ret = 1; - char buf1[8192], buf2[8192]; - - if ((fd1 = open_nofollow(path1, O_RDONLY)) < 0 || - fstat(fd1, &st1) || !S_ISREG(st1.st_mode)) { - if (fd1 < 0 && errno == ELOOP) - /* maybe this is a symbolic link? */ - return do_symlinks_match(path1, path2); - ret = 0; - } else if ((fd2 = open_nofollow(path2, O_RDONLY)) < 0 || - fstat(fd2, &st2) || !S_ISREG(st2.st_mode)) { - ret = 0; - } - - if (ret) - /* to match, neither must be executable, or both */ - ret = !(st1.st_mode & 0111) == !(st2.st_mode & 0111); - - if (ret) - ret = st1.st_size == st2.st_size; - - while (ret) { - ssize_t len1 = read_in_full(fd1, buf1, sizeof(buf1)); - ssize_t len2 = read_in_full(fd2, buf2, sizeof(buf2)); - - if (len1 < 0 || len2 < 0 || len1 != len2) - ret = 0; /* read error or different file size */ - else if (!len1) /* len2 is also 0; hit EOF on both */ - break; /* ret is still true */ - else - ret = !memcmp(buf1, buf2, len1); - } - - if (fd1 >= 0) - close(fd1); - if (fd2 >= 0) - close(fd2); - - return ret; -} diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c index 0e0de218076..f69709d674f 100644 --- a/t/helper/test-path-utils.c +++ b/t/helper/test-path-utils.c @@ -495,16 +495,6 @@ int cmd__path_utils(int argc, const char **argv) return !!res; } - if (argc == 4 && !strcmp(argv[1], "do_files_match")) { - int ret = do_files_match(argv[2], argv[3]); - - if (ret) - printf("equal\n"); - else - printf("different\n"); - return !ret; - } - fprintf(stderr, "%s: unknown function name: %s\n", argv[0], argv[1] ? argv[1] : "(there was none)"); return 1; diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index 73d0e1a7f10..68e29c904a6 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -560,45 +560,4 @@ test_expect_success !VALGRIND,RUNTIME_PREFIX,CAN_EXEC_IN_PWD '%(prefix)/ works' test_cmp expect actual ' -test_expect_success 'do_files_match()' ' - test_seq 0 10 >0-10.txt && - test_seq -1 10 >-1-10.txt && - test_seq 1 10 >1-10.txt && - test_seq 1 9 >1-9.txt && - test_seq 0 8 >0-8.txt && - - test-tool path-utils do_files_match 0-10.txt 0-10.txt >out && - - assert_fails() { - test_must_fail \ - test-tool path-utils do_files_match "$1" "$2" >out && - grep different out - } && - - assert_fails 0-8.txt 1-9.txt && - assert_fails -1-10.txt 0-10.txt && - assert_fails 1-10.txt 1-9.txt && - assert_fails 1-10.txt .git && - assert_fails does-not-exist 1-10.txt && - - if test_have_prereq FILEMODE - then - cp 0-10.txt 0-10.x && - chmod a+x 0-10.x && - assert_fails 0-10.txt 0-10.x - fi && - - if test_have_prereq SYMLINKS - then - ln -sf 0-10.txt symlink && - ln -s 0-10.txt another-symlink && - ln -s over-the-ocean yet-another-symlink && - ln -s "$PWD/0-10.txt" absolute-symlink && - assert_fails 0-10.txt symlink && - test-tool path-utils do_files_match symlink another-symlink && - assert_fails symlink yet-another-symlink && - assert_fails symlink absolute-symlink - fi -' - test_done