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

Re: [PATCH v4] remote rename/remove: gently handle remote.pushDefault config

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 4, 2020, 20:11 UTC
Message-ID
<xmqqv9om6rkk.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<nycvar.QRO.7.76.6.2002021911260.46@tvgsbejvaqbjf.bet>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
Show 11 quoted lines
>> +	struct push_default_info* info = cb;
>> +	if (strcmp(key, "remote.pushdefault") || strcmp(value, info->old_name))
>> +		return 0;
>
> We will have to be careful to not segfault if a user has this in their
> config:
>
> 	[remote]
> 		pushDefault
>
> i.e. we have to insert `!value || ` before the call to `strcmp()`.

True. The primary reader in remote.c::handle_config() uses git_config_string() that complains that the variable is not bool, but we should reat end-user input as something suspicious and protect us against it.

Show 6 quoted lines
> Concretely, I believe that the patched code will misbehave in this
> scenario:
>
> 	git config --global remote.pushDefault january
> 	git config remote.pushDefault february
> 	git remote rename january march
Good to see careful analysis.  Thanks.
Show 5 quoted lines
>> +static void handle_push_default(const char* old_name, const char* new_name)
>
> That name probably wants to convey better that the push default is handled
> in the `mv`/`rm` commands here, not in any other command. Maybe
> `handle_modified_push_default_remote()`?
Also, the asterisk sticks to the variable not the type ;-)
Show 7 quoted lines
>> +{
>> +	struct push_default_info push_default = {
>> +		old_name, CONFIG_SCOPE_UNKNOWN, STRBUF_INIT, -1 };
>
> Personally, I would prefer the closing bracket to be on a new line,
> followed by an empty line to separate the variable declaration from the
> following statements.
Yes, yes.
Previous: Johannes Schindelin
Message 3 of 3 in “remote rename/remove: gently handle remote.pushDefault config”
  1. remote rename/remove: gently handle remote.pushDefault configBert Wesarg, Feb 1, 2020
  2. Johannes SchindelinFeb 2, 2020
  3. Junio C HamanoFeb 4, 2020

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.