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

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

From
Jeff King <peff@peff.net>
Date
Jul 26, 2024, 05:02 UTC
Message-ID
<20240726050253.GC642208@coredump.intra.peff.net>
In-Reply-To
<20240723021900.388020-3-gitster@pobox.com>
On Mon, Jul 22, 2024 at 07:18:59PM -0700, Junio C Hamano wrote:
Show 10 quoted lines
> The pathname of a repository comes from getcwd() and it could be a
> path aliased via symbolic links, e.g., the real directory may be
> /home/u/repository but a symbolic link /home/u/repo may point at it,
> and the clone request may come as "git clone file:///home/u/repo/"
> 
> A request to check if /home/u/repository is safe would be rejected
> if the safe.directory configuration allows /home/u/repo/ but not its
> alias /home/u/repository/.  Normalize the paths configured for the
> safe.directory configuration variable before comparing them with the
> path being checked.

This may be a dumb question, but... will this always work, if the config option is not necessarily an exact path, and might have globbing characters in it?

We don't currently treat it like a wildmatch glob, but:
  1. We do allow "/*" on the end. Should we strip that off so it doesn't
     confuse the realpath lookup?
  2. This is shutting the door on using wildmatch or similar in the
     future. Is that OK?
Show 13 quoted lines
> @@ -1236,6 +1236,16 @@ static int safe_directory_cb(const char *key, const char *value,
>  
>  		if (!git_config_pathname(&allowed, key, value)) {
>  			const char *check = allowed ? allowed : value;
> +			char *to_free = real_pathdup(check, 0);
> +
> +			if (!to_free) {
> +				warning(_("safe.directory '%s' cannot be normalized"),
> +					check);
> +				goto next;
> +			} else {
> +				check = to_free;
> +			}

I'm not sure about this warning. I don't know how people use this config in the real world, but it seems plausible to me they might have:

  [safe]
  directory = /home/me/this/always/exists
  directory = /home/me/this/might/not/exist

perhaps because they're using a generic config file across multiple machines. And then they'd get:

  warning: safe.directory '/home/me/this/might/not/exist' cannot be normalized

on every invocation (at least ones that need to consult safe.directory). Should we be quiet there, and maybe fall back to using the non-normalized path (though I guess if we could not normalize it, that probably means it could never match anyway)?

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 15 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.