All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org,  Phillip Wood <phillip.wood123@gmail.com>
Subject: Re: [PATCH v3 2/3] safe.directory: normalize the configured path
Date: Tue, 30 Jul 2024 09:22:09 -0700	[thread overview]
Message-ID: <xmqqv80metou.fsf@gitster.g> (raw)
In-Reply-To: <20240730074307.GB562212@coredump.intra.peff.net> (Jeff King's message of "Tue, 30 Jul 2024 03:43:07 -0400")

Jeff King <peff@peff.net> writes:

> On Mon, Jul 29, 2024 at 06:10:03PM -0700, Junio C Hamano wrote:
>
>> @@ -1236,14 +1236,43 @@ static int safe_directory_cb(const char *key, const char *value,
>>  
>>  		if (!git_config_pathname(&allowed, key, value)) {
>>  			const char *check = allowed ? allowed : value;
>> -			if (ends_with(check, "/*")) {
>> -				size_t len = strlen(check);
>> -				if (!fspathncmp(check, data->path, len - 1))
>
> BTW, one oddity I noticed in the existing code:
>
> Under what circumstances will "allowed" be NULL in that ternary? I think
> if git_config_pathname() returns non-zero, then we called
> interpolate_path(). It can return NULL, but in that case
> git_config_pathname() will die(). We might change that later, but then
> I'd expect it to return non-zero. So I suspect the whole "check"
> variable could just be dropped in favor of using "allowed".
>
> Obviously not new in your patch, but maybe worth fixing while in the
> area? I think it comes from an evil merge in b8bdb2f283 (Merge branch
> 'jc/safe-directory-leading-path', 2024-06-12).

I think it deserves to be a separate change, probably a preliminary
clean-up, as it predates that by a few years, and goes back to the
initial introduction of the safe.directory feature.  The merge you
found had this bit:

diff --cc setup.c
index e47946d0e7,4c5de0960b..e112545f71
--- a/setup.c
+++ b/setup.c
@@@ -1230,13 -1176,21 +1230,20 @@@ static int safe_directory_cb(const cha
  	} else if (!strcmp(value, "*")) {
  		data->is_safe = 1;
  	} else {
- 		char *interpolated = NULL;
- 
- 		if (!git_config_pathname(&interpolated, key, value) &&
- 		    !fspathcmp(data->path, interpolated ? interpolated : value))
- 			data->is_safe = 1;
- 
- 		free(interpolated);
 ...


Notice that in the original, the code is prepared for the case where
interpolated is NULL when fspathcmp() needs to use it or value,
which is when git_config_pathname() returned 0/success.

It came from 8959555c (setup_git_directory(): add an owner check for
the top-level directory, 2022-03-02) that introduced the
safe.directory feature:

+		if (!git_config_pathname(&interpolated, key, value) &&
+		    !fspathcmp(data->path, interpolated ? interpolated : value))
+			data->is_safe = 1;

where it shared the same assumption.

  reply	other threads:[~2024-07-30 16:22 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-20 22:09 [PATCH 0/2] safe.directory clean-up Junio C Hamano
2024-07-20 22:09 ` [PATCH 1/2] safe.directory: normalize the checked path Junio C Hamano
2024-07-20 22:09 ` [PATCH 2/2] safe.directory: normalize the configured path Junio C Hamano
2024-07-20 22:09 ` [PATCH 3/2] setup: use a single return path in setup_git_directory*() Junio C Hamano
2024-07-20 22:09 ` [PATCH 4/2] setup: cache normalized safe.directory configuration Junio C Hamano
2024-07-23  2:18 ` [PATCH v2 0/3] safe.directory clean-up Junio C Hamano
2024-07-23  2:18   ` [PATCH v2 1/3] safe.directory: normalize the checked path Junio C Hamano
2024-07-23  2:18   ` [PATCH v2 2/3] safe.directory: normalize the configured path Junio C Hamano
2024-07-25  9:45     ` Phillip Wood
2024-07-25 16:11       ` Junio C Hamano
2024-08-14 13:20         ` Phillip Wood
2024-08-14 17:15           ` Junio C Hamano
2024-08-15  9:51             ` Phillip Wood
2024-08-15 14:43               ` Junio C Hamano
2024-07-26  5:02     ` Jeff King
2024-07-26 15:02       ` Junio C Hamano
2024-07-27 22:05         ` Jeff King
2024-07-23  2:19   ` [PATCH v2 3/3] safe.directory: setting safe.directory="." allows the "current" directory Junio C Hamano
2024-07-25  9:45     ` Phillip Wood
2024-07-25 16:12       ` Junio C Hamano
2024-07-25  9:45   ` [PATCH v2 0/3] safe.directory clean-up Phillip Wood
2024-07-25 16:14     ` Junio C Hamano
2024-07-30  1:10   ` [PATCH v3 " Junio C Hamano
2024-07-30  1:10     ` [PATCH v3 1/3] safe.directory: normalize the checked path Junio C Hamano
2024-07-30  1:10     ` [PATCH v3 2/3] safe.directory: normalize the configured path Junio C Hamano
2024-07-30  7:31       ` Jeff King
2024-07-30 16:03         ` Junio C Hamano
2024-07-30 20:08           ` Jeff King
2024-07-30  7:43       ` Jeff King
2024-07-30 16:22         ` Junio C Hamano [this message]
2024-07-30 17:56           ` safe.directory: preliminary clean-up Junio C Hamano
2024-07-30 20:13             ` Jeff King
2024-07-30 20:10           ` [PATCH v3 2/3] safe.directory: normalize the configured path Jeff King
2024-07-30  1:10     ` [PATCH v3 3/3] safe.directory: setting safe.directory="." allows the "current" directory Junio C Hamano
2024-07-30 18:43     ` [PATCH v4 0/4] safe.directory clean-up Junio C Hamano
2024-07-30 18:43       ` [PATCH v4 1/4] safe.directory: preliminary clean-up Junio C Hamano
2024-07-30 18:43       ` [PATCH v4 2/4] safe.directory: normalize the checked path Junio C Hamano
2024-07-30 18:43       ` [PATCH v4 3/4] safe.directory: normalize the configured path Junio C Hamano
2024-07-30 18:43       ` [PATCH v4 4/4] safe.directory: setting safe.directory="." allows the "current" directory Junio C Hamano

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=xmqqv80metou.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    --cc=phillip.wood123@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.