Re: [PATCH 2/3] setup: fix safe.directory key not being checked
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Apr 13, 2022, 16:34 UTC
- Message-ID
- <xmqqr1619c2v.fsf@gitster.g>
- In-Reply-To
- <8a06688c121195f21472e3e49efd2b034b1537fc.1649863951.git.gitgitgadget@gmail.com>
"Matheus Valadares via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 6 quoted lines
> From: Matheus Valadares <me@m28.io> > > It seems that nothing is ever checking to make sure the safe directories > in the configs actually have the key safe.directory, so some unrelated > config that has a value with a certain directory would also make it a > safe directory.
Good finding, and the fix is straight-forward and obviously correct. Thanks.
Show 6 quoted lines
> Signed-off-by: Matheus Valadares <me@m28.io> > Signed-off-by: Derrick Stolee <derrickstolee@github.com> > --- > setup.c | 3 +++ > t/t0033-safe-directory.sh | 5 +++++ > 2 files changed, 8 insertions(+)
Show 30 quoted lines
> diff --git a/setup.c b/setup.c
> index f54f449008a..a995c359c32 100644
> --- a/setup.c
> +++ b/setup.c
> @@ -1100,6 +1100,9 @@ static int safe_directory_cb(const char *key, const char *value, void *d)
> {
> struct safe_directory_data *data = d;
>
> + if (strcmp(key, "safe.directory"))
> + return 0;
> +
> if (!value || !*value)
> data->is_safe = 0;
> else {
> diff --git a/t/t0033-safe-directory.sh b/t/t0033-safe-directory.sh
> index 9380ff3d017..6f33c0dfefa 100755
> --- a/t/t0033-safe-directory.sh
> +++ b/t/t0033-safe-directory.sh
> @@ -21,6 +21,11 @@ test_expect_success 'safe.directory does not match' '
> expect_rejected_dir
> '
>
> +test_expect_success 'path exist as different key' '
> + git config --global foo.bar "$(pwd)" &&
> + expect_rejected_dir
> +'
> +
> test_expect_success 'safe.directory matches' '
> git config --global --add safe.directory "$(pwd)" &&
> git status