From: Kyle Lippincott <spectral@google.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 06/21] builtin/config: check for writeability after source is set up
Date: Fri, 10 May 2024 13:46:43 -0700 [thread overview]
Message-ID: <CAO_smVhahWTvH4ycDGoRd2WeUnbNs=8Ukq5L17gRYn9kdE-zjA@mail.gmail.com> (raw)
In-Reply-To: <edfd7caa39ab990faf5b49a6c572a612a35dbdd5.1715339393.git.ps@pks.im>
On Fri, May 10, 2024 at 4:26 AM Patrick Steinhardt <ps@pks.im> wrote:
>
> 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.
Minor nit/question since I'm still pretty inexperienced w/ the project norms:
Since this is a bug fix/behavior change, can we reorder the series so
this comes before (or after) the rest of the cleanups? I'm assuming
this fix would be something that could stand alone in its own series
even if we weren't making the other changes.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> 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
> --
> 2.45.GIT
>
next prev parent reply other threads:[~2024-05-10 20:47 UTC|newest]
Thread overview: 81+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-10 11:24 [PATCH 00/21] builtin/config: remove global state Patrick Steinhardt
2024-05-10 11:24 ` [PATCH 01/21] builtin/config: stop printing full usage on misuse Patrick Steinhardt
2024-05-10 11:24 ` [PATCH 02/21] builtin/config: move legacy mode into its own function Patrick Steinhardt
2024-05-10 11:24 ` [PATCH 03/21] builtin/config: move subcommand options into `cmd_config()` Patrick Steinhardt
2024-05-10 11:24 ` [PATCH 04/21] builtin/config: move legacy " Patrick Steinhardt
2024-05-10 11:24 ` [PATCH 05/21] builtin/config: move actions into `cmd_config_actions()` Patrick Steinhardt
2024-05-10 20:42 ` Kyle Lippincott
2024-05-13 10:20 ` Patrick Steinhardt
2024-05-10 11:24 ` [PATCH 06/21] builtin/config: check for writeability after source is set up Patrick Steinhardt
2024-05-10 20:46 ` Kyle Lippincott [this message]
2024-05-13 10:21 ` Patrick Steinhardt
2024-05-10 11:24 ` [PATCH 07/21] config: make the config source const Patrick Steinhardt
2024-05-10 11:25 ` [PATCH 08/21] builtin/config: refactor functions to have common exit paths Patrick Steinhardt
2024-05-10 11:25 ` [PATCH 09/21] builtin/config: move location options into local variables Patrick Steinhardt
2024-05-10 11:34 ` Patrick Steinhardt
2024-05-10 11:25 ` [PATCH 10/21] builtin/config: move display " Patrick Steinhardt
2024-05-10 11:25 ` [PATCH 11/21] builtin/config: move type options into display options Patrick Steinhardt
2024-05-10 11:25 ` [PATCH 12/21] builtin/config: move default value " Patrick Steinhardt
2024-05-10 11:25 ` [PATCH 13/21] builtin/config: move `respect_includes_opt` into location options Patrick Steinhardt
2024-05-10 11:25 ` [PATCH 14/21] builtin/config: convert `do_not_match` to a local variable Patrick Steinhardt
2024-05-11 16:42 ` Eric Sunshine
2024-05-10 11:25 ` [PATCH 15/21] builtin/config: convert `value_pattern` " Patrick Steinhardt
2024-05-10 11:25 ` [PATCH 16/21] builtin/config: convert `regexp` " Patrick Steinhardt
2024-05-10 11:25 ` [PATCH 17/21] builtin/config: convert `key_regexp` " Patrick Steinhardt
2024-05-10 11:25 ` [PATCH 18/21] builtin/config: convert `key` " Patrick Steinhardt
2024-05-10 11:25 ` [PATCH 19/21] builtin/config: track "fixed value" option via flags only Patrick Steinhardt
2024-05-11 16:52 ` Eric Sunshine
2024-05-10 11:26 ` [PATCH 20/21] builtin/config: convert flags to a local variable Patrick Steinhardt
2024-05-10 11:26 ` [PATCH 21/21] builtin/config: pass data between callbacks via local variables Patrick Steinhardt
2024-05-10 17:40 ` [PATCH 00/21] builtin/config: remove global state Junio C Hamano
2024-05-10 23:08 ` Kyle Lippincott
2024-05-13 10:21 ` [PATCH v2 " Patrick Steinhardt
2024-05-13 10:22 ` [PATCH v2 01/21] builtin/config: stop printing full usage on misuse Patrick Steinhardt
2024-05-13 10:22 ` [PATCH v2 02/21] builtin/config: move legacy mode into its own function Patrick Steinhardt
2024-05-13 10:22 ` [PATCH v2 03/21] builtin/config: move subcommand options into `cmd_config()` Patrick Steinhardt
2024-05-13 10:22 ` [PATCH v2 04/21] builtin/config: move legacy " Patrick Steinhardt
2024-05-13 10:22 ` [PATCH v2 05/21] builtin/config: move actions into `cmd_config_actions()` Patrick Steinhardt
2024-05-13 10:22 ` [PATCH v2 06/21] builtin/config: check for writeability after source is set up Patrick Steinhardt
2024-05-14 21:45 ` Taylor Blau
2024-05-15 5:58 ` Patrick Steinhardt
2024-05-13 10:22 ` [PATCH v2 07/21] config: make the config source const Patrick Steinhardt
2024-05-13 10:22 ` [PATCH v2 08/21] builtin/config: refactor functions to have common exit paths Patrick Steinhardt
2024-05-13 10:22 ` [PATCH v2 09/21] builtin/config: move location options into local variables Patrick Steinhardt
2024-05-13 10:22 ` [PATCH v2 10/21] builtin/config: move display " Patrick Steinhardt
2024-05-13 10:22 ` [PATCH v2 11/21] builtin/config: move type options into display options Patrick Steinhardt
2024-05-13 10:23 ` [PATCH v2 12/21] builtin/config: move default value " Patrick Steinhardt
2024-05-13 10:23 ` [PATCH v2 13/21] builtin/config: move `respect_includes_opt` into location options Patrick Steinhardt
2024-05-13 10:23 ` [PATCH v2 14/21] builtin/config: convert `do_not_match` to a local variable Patrick Steinhardt
2024-05-13 10:23 ` [PATCH v2 15/21] builtin/config: convert `value_pattern` " Patrick Steinhardt
2024-05-13 10:23 ` [PATCH v2 16/21] builtin/config: convert `regexp` " Patrick Steinhardt
2024-05-13 10:23 ` [PATCH v2 17/21] builtin/config: convert `key_regexp` " Patrick Steinhardt
2024-05-13 10:23 ` [PATCH v2 18/21] builtin/config: convert `key` " Patrick Steinhardt
2024-05-13 10:23 ` [PATCH v2 19/21] builtin/config: track "fixed value" option via flags only Patrick Steinhardt
2024-05-13 10:23 ` [PATCH v2 20/21] builtin/config: convert flags to a local variable Patrick Steinhardt
2024-05-13 10:23 ` [PATCH v2 21/21] builtin/config: pass data between callbacks via local variables Patrick Steinhardt
2024-05-13 21:57 ` [PATCH v2 00/21] builtin/config: remove global state Kyle Lippincott
2024-05-14 14:48 ` Junio C Hamano
2024-05-14 14:52 ` Patrick Steinhardt
2024-05-15 5:53 ` Patrick Steinhardt
2024-05-15 6:41 ` [PATCH v3 " Patrick Steinhardt
2024-05-15 6:41 ` [PATCH v3 01/21] builtin/config: stop printing full usage on misuse Patrick Steinhardt
2024-05-15 6:41 ` [PATCH v3 02/21] builtin/config: move legacy mode into its own function Patrick Steinhardt
2024-05-15 6:41 ` [PATCH v3 03/21] builtin/config: move subcommand options into `cmd_config()` Patrick Steinhardt
2024-05-15 6:41 ` [PATCH v3 04/21] builtin/config: move legacy " Patrick Steinhardt
2024-05-15 6:41 ` [PATCH v3 05/21] builtin/config: move actions into `cmd_config_actions()` Patrick Steinhardt
2024-05-15 6:42 ` [PATCH v3 06/21] builtin/config: check for writeability after source is set up Patrick Steinhardt
2024-05-15 6:42 ` [PATCH v3 07/21] config: make the config source const Patrick Steinhardt
2024-05-15 6:42 ` [PATCH v3 08/21] builtin/config: refactor functions to have common exit paths Patrick Steinhardt
2024-05-15 6:42 ` [PATCH v3 09/21] builtin/config: move location options into local variables Patrick Steinhardt
2024-05-15 6:42 ` [PATCH v3 10/21] builtin/config: move display " Patrick Steinhardt
2024-05-15 6:42 ` [PATCH v3 11/21] builtin/config: move type options into display options Patrick Steinhardt
2024-05-15 6:42 ` [PATCH v3 12/21] builtin/config: move default value " Patrick Steinhardt
2024-05-15 6:42 ` [PATCH v3 13/21] builtin/config: move `respect_includes_opt` into location options Patrick Steinhardt
2024-05-15 6:42 ` [PATCH v3 14/21] builtin/config: convert `do_not_match` to a local variable Patrick Steinhardt
2024-05-15 6:42 ` [PATCH v3 15/21] builtin/config: convert `value_pattern` " Patrick Steinhardt
2024-05-15 6:42 ` [PATCH v3 16/21] builtin/config: convert `regexp` " Patrick Steinhardt
2024-05-15 6:42 ` [PATCH v3 17/21] builtin/config: convert `key_regexp` " Patrick Steinhardt
2024-05-15 6:42 ` [PATCH v3 18/21] builtin/config: convert `key` " Patrick Steinhardt
2024-05-15 6:43 ` [PATCH v3 19/21] builtin/config: track "fixed value" option via flags only Patrick Steinhardt
2024-05-15 6:43 ` [PATCH v3 20/21] builtin/config: convert flags to a local variable Patrick Steinhardt
2024-05-15 6:43 ` [PATCH v3 21/21] builtin/config: pass data between callbacks via local variables Patrick Steinhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAO_smVhahWTvH4ycDGoRd2WeUnbNs=8Ukq5L17gRYn9kdE-zjA@mail.gmail.com' \
--to=spectral@google.com \
--cc=git@vger.kernel.org \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).