git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 2/3] safe.directory: normalize the configured path

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 30, 2024, 16:22 UTC
Message-ID
<xmqqv80metou.fsf@gitster.g>
In-Reply-To
<20240730074307.GB562212@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 22 quoted lines
> 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.
Previous: Jeff KingNext: Junio C Hamano
Message 30 of 39 in “safe.directory clean-up”
  1. 0/2 safe.directory clean-upJunio C Hamano, Jul 20, 2024
  2. 1/2 safe.directory: normalize the checked pathJunio C Hamano, Jul 20, 2024
  3. 2/2 safe.directory: normalize the configured pathJunio C Hamano, Jul 20, 2024
  4. 3/2 setup: use a single return path in setup_git_directory*()Junio C Hamano, Jul 20, 2024
  5. 4/2 setup: cache normalized safe.directory configurationJunio C Hamano, Jul 20, 2024
  6. 0/3 safe.directory clean-upJunio C Hamano, Jul 23, 2024
  7. 1/3 safe.directory: normalize the checked pathJunio C Hamano, Jul 23, 2024
  8. 2/3 safe.directory: normalize the configured pathJunio C Hamano, Jul 23, 2024
  9. Phillip WoodJul 25, 2024
  10. Junio C HamanoJul 25, 2024
  11. Phillip WoodAug 14, 2024
  12. Junio C HamanoAug 14, 2024
  13. Phillip WoodAug 15, 2024
  14. Junio C HamanoAug 15, 2024
  15. Jeff KingJul 26, 2024
  16. Junio C HamanoJul 26, 2024
  17. Jeff KingJul 27, 2024
  18. 3/3 safe.directory: setting safe.directory="." allows the "current" directoryJunio C Hamano, Jul 23, 2024
  19. Phillip WoodJul 25, 2024
  20. Junio C HamanoJul 25, 2024
  21. Phillip WoodJul 25, 2024
  22. Junio C HamanoJul 25, 2024
  23. 0/3 safe.directory clean-upJunio C Hamano, Jul 30, 2024
  24. 1/3 safe.directory: normalize the checked pathJunio C Hamano, Jul 30, 2024
  25. 2/3 safe.directory: normalize the configured pathJunio C Hamano, Jul 30, 2024
  26. Jeff KingJul 30, 2024
  27. Junio C HamanoJul 30, 2024
  28. Jeff KingJul 30, 2024
  29. Jeff KingJul 30, 2024
  30. Junio C HamanoJul 30, 2024
  31. safe.directory: preliminary clean-upJunio C Hamano, Jul 30, 2024
  32. Jeff KingJul 30, 2024
  33. Jeff KingJul 30, 2024
  34. 3/3 safe.directory: setting safe.directory="." allows the "current" directoryJunio C Hamano, Jul 30, 2024
  35. 0/4 safe.directory clean-upJunio C Hamano, Jul 30, 2024
  36. 2/4 safe.directory: normalize the checked pathJunio C Hamano, Jul 30, 2024
  37. 1/4 safe.directory: preliminary clean-upJunio C Hamano, Jul 30, 2024
  38. 4/4 safe.directory: setting safe.directory="." allows the "current" directoryJunio C Hamano, Jul 30, 2024
  39. 3/4 safe.directory: normalize the configured pathJunio C Hamano, Jul 30, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.