From patchwork Fri May 10 11:24:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13661372 Received: from wfout8-smtp.messagingengine.com (wfout8-smtp.messagingengine.com [64.147.123.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5CD881708B7 for ; Fri, 10 May 2024 11:24:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715340299; cv=none; b=dnuBfjhxm6cnYa/GN2MiKQEJ1vPqiImpwJDA59zs05iD70XwzLpc5zgTN/wtnOw2HlTVzKm6jkOCZ1LM5c5JUcSKZ30D/OV31+13mJ7vM7CNgr66l/CW65hFFA+iasFyrCrLwSjEg9ut8jO1gPcatY2MWtpKXjbp3dq0j7tiFm8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715340299; c=relaxed/simple; bh=BHUQqySSHNFmrdsUpUoik7TcbOOpErpdyFp8NdWAbJU=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qrD80j6z5EgOymvtkUWgJWSN/m5UQ/GEbSLOHGTXl+bwrth7kn+8sTuy96xJUg2meMAOutbDqvofF8jUJHDgAV+KOhVlW2c18k/Q3KT4A2fvZLkflHf02qoJuaFPcKkVh9OgWajE38TQ8IH/fHUmD7FK12Bl0DaqPo3Ygx+RMKE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=lfE9gskv; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=hNVzIQyq; arc=none smtp.client-ip=64.147.123.151 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="lfE9gskv"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="hNVzIQyq" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.west.internal (Postfix) with ESMTP id 7599E1C00095 for ; Fri, 10 May 2024 07:24:56 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Fri, 10 May 2024 07:24:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1715340296; x=1715426696; bh=yXUUjlD/9Y tQZ9/5DOXjUVR3530sjI3w7Z8rW0/Sd1M=; b=lfE9gskvIlQ6pxX9zzBuxs/uFY bBRV9y0TjsKz3Ytbu46juyKq/p4+vh17w6Ig3ugb6CMBcpPqvN1/Jzpl/lAWUBE8 wouP+A/VNZsM8nczcwe/cxoy1PHPzQE4SY+wtpe6tl43Q/q8QasFMZCGONnHGlO6 rNnGblo8i21TKkpsrEyS/hPG536hvva+qfC0bfHJ7BdUVT4blkIVbA5irMKab9F0 2jGYydJ8oqgaZjqPxZNVRaqIWNScEsvf4SNb7asFCvpafOHydjqdXu8CgV9wiKOR wA1Emu4NOrmW1PayzeYUhA09Xj1XitwYQulgpyTe5cVyHHs7+h1P+GxL6gQw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715340296; x=1715426696; bh=yXUUjlD/9YtQZ9/5DOXjUVR3530s jI3w7Z8rW0/Sd1M=; b=hNVzIQyq0/e5WMYVlRxzbMS4zfrk9zUOo58tCKGTkzmt U2fST4A2tS/WgzUR+pt0l+cDbepZGtdtfdSBJdy4QvYY0T7xo9/nBySvZWpfoNoA E83TZ+YDbEs3krrv6bVvHvCwu/SbbNRaNSJwRu42KpNXaGzMN9mLLJ4kFadvwwuh prkKpJtJuYyNi5miDHcLgEdAo8opMey3LSebUArU/Sh//xIusN/H1sRA9UQC8o5z noNhmEa7SbtJ+/DbPTTR+MuMG8AU3wQQ8bw/LSNQadgynJwCvENKJq7+8LoZmK2W p3JbtOyJclPQvtNXjcR2GUBIilnrWGSFp+lgP17k6g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdefkedgfeelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgepvdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 10 May 2024 07:24:55 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id b2e8a579 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Fri, 10 May 2024 11:24:42 +0000 (UTC) Date: Fri, 10 May 2024 13:24:52 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 06/21] builtin/config: check for writeability after source is set up Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `check_write()` function verifies that we do not try to write to a config source that cannot be written to, like for example stdin. But while the new subcommands do call this function, they do so before calling `handle_config_location()`. Consequently, we only end up checking the default config location for writeability, not the location that was actually specified by the caller of git-config(1). Fix this by calling `check_write()` after `handle_config_location()`. We will further clarify the relationship between those two functions in a subsequent commit where we remove the global state that both implicitly rely on. Signed-off-by: Patrick Steinhardt --- builtin/config.c | 10 +++++----- t/t1300-config.sh | 6 ++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 8f3342b593..9295a2f737 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -843,7 +843,6 @@ static int cmd_config_set(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, opts, builtin_config_set_usage, PARSE_OPT_STOP_AT_NON_OPTION); - check_write(); check_argc(argc, 2, 2); if ((flags & CONFIG_FLAGS_FIXED_VALUE) && !value_pattern) @@ -856,6 +855,7 @@ static int cmd_config_set(int argc, const char **argv, const char *prefix) comment = git_config_prepare_comment_string(comment_arg); handle_config_location(prefix); + check_write(); value = normalize_value(argv[0], argv[1], &default_kvi); @@ -891,13 +891,13 @@ static int cmd_config_unset(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, opts, builtin_config_unset_usage, PARSE_OPT_STOP_AT_NON_OPTION); - check_write(); check_argc(argc, 1, 1); if ((flags & CONFIG_FLAGS_FIXED_VALUE) && !value_pattern) die(_("--fixed-value only applies with 'value-pattern'")); handle_config_location(prefix); + check_write(); if ((flags & CONFIG_FLAGS_MULTI_REPLACE) || value_pattern) return git_config_set_multivar_in_file_gently(given_config_source.file, @@ -918,10 +918,10 @@ static int cmd_config_rename_section(int argc, const char **argv, const char *pr argc = parse_options(argc, argv, prefix, opts, builtin_config_rename_section_usage, PARSE_OPT_STOP_AT_NON_OPTION); - check_write(); check_argc(argc, 2, 2); handle_config_location(prefix); + check_write(); ret = git_config_rename_section_in_file(given_config_source.file, argv[0], argv[1]); @@ -943,10 +943,10 @@ static int cmd_config_remove_section(int argc, const char **argv, const char *pr argc = parse_options(argc, argv, prefix, opts, builtin_config_remove_section_usage, PARSE_OPT_STOP_AT_NON_OPTION); - check_write(); check_argc(argc, 1, 1); handle_config_location(prefix); + check_write(); ret = git_config_rename_section_in_file(given_config_source.file, argv[0], NULL); @@ -997,10 +997,10 @@ static int cmd_config_edit(int argc, const char **argv, const char *prefix) }; argc = parse_options(argc, argv, prefix, opts, builtin_config_edit_usage, 0); - check_write(); check_argc(argc, 0, 0); handle_config_location(prefix); + check_write(); return show_editor(); } diff --git a/t/t1300-config.sh b/t/t1300-config.sh index d90a69b29f..9de2d95f06 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -2835,6 +2835,12 @@ test_expect_success 'specifying multiple modes causes failure' ' test_cmp expect err ' +test_expect_success 'writing to stdin is rejected' ' + echo "fatal: writing to stdin is not supported" >expect && + test_must_fail git config ${mode_set} --file - foo.bar baz 2>err && + test_cmp expect err +' + done test_done