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

Re: [PATCH v3] setup: don't die if realpath(3) fails on getcwd(3)

From
Kevin Locke <kevin@kevinlocke.name>
Date
May 24, 2022, 18:00 UTC
Message-ID
<Yo0dS550l2NCmx9O@kevinlocke.name>
In-Reply-To
<dafc8178-d213-ffd0-9e2a-32ac88307b39@github.com>
On Tue, 2022-05-24 at 13:41 -0400, Derrick Stolee wrote:
Show 22 quoted lines
> On 5/24/2022 10:51 AM, Kevin Locke wrote:> -	/* Normalize the directory */
>> -	strbuf_realpath(&tmp, tmp_original_cwd, 1);
>> -	free((char*)tmp_original_cwd);
>> -	tmp_original_cwd = NULL;
>> -	startup_info->original_cwd = strbuf_detach(&tmp, NULL);
>> +	/* Try to normalize the directory. */
>> +	if (strbuf_realpath(&tmp, tmp_original_cwd, 0)) {
>> +		free((char*)tmp_original_cwd);
>> +		tmp_original_cwd = NULL;
>> +		startup_info->original_cwd = strbuf_detach(&tmp, NULL);
>> +	} else {
>> +		trace2_data_string("setup", the_repository,
>> +				   "realpath-path", tmp_original_cwd);
>> +		trace2_data_string("setup", the_repository,
>> +				   "realpath-failure", strerror(errno));
>> +		tmp_original_cwd = NULL;
> 
> I didn't catch this in v2, but should this line instead be
> 
> 		startup_info->original_cwd = NULL;
> 
> ? Especially based on this comment:

No worries. It's a good question. Setting startup_info->original_cwd to NULL is handled by the no_prevention_needed label. But I just realized it's not actually required in this case, since original_cwd is NULL when setup_original_cwd() is called. I should probably return rather than jumping to no_prevention_needed from the else block to avoid the unnecessary free(NULL) and assignment.

Your comment made me realize that v2 and later neglect to free tmp_original_cwd when strbuf_realpath() fails. How embarrassing.

I'll send an update to fix both those issues shortly.

Thanks again, Kevin

Previous: Derrick StoleeNext: Kevin Locke
Message 17 of 22 in “setup: don't die if realpath(3) fails on getcwd(3)”
  1. setup: don't die if realpath(3) fails on getcwd(3)Kevin Locke, May 19, 2022
  2. Junio C HamanoMay 20, 2022
  3. Elijah NewrenMay 21, 2022
  4. Kevin LockeMay 21, 2022
  5. Derrick StoleeMay 23, 2022
  6. setup: don't die if realpath(3) fails on getcwd(3)Kevin Locke, May 21, 2022
  7. Derrick StoleeMay 23, 2022
  8. Kevin LockeMay 24, 2022
  9. Elijah NewrenMay 24, 2022
  10. Derrick StoleeMay 24, 2022
  11. Elijah NewrenMay 25, 2022
  12. Ævar Arnfjörð BjarmasonMay 27, 2022
  13. Elijah NewrenMay 28, 2022
  14. setup: don't die if realpath(3) fails on getcwd(3)Kevin Locke, May 24, 2022
  15. Elijah NewrenMay 24, 2022
  16. Derrick StoleeMay 24, 2022
  17. Kevin LockeMay 24, 2022
  18. setup: don't die if realpath(3) fails on getcwd(3)Kevin Locke, May 24, 2022
  19. Derrick StoleeMay 24, 2022
  20. Junio C HamanoMay 24, 2022
  21. Elijah NewrenMay 25, 2022
  22. Junio C HamanoMay 25, 2022

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.