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

Re: [PATCH] config: arbitrary number of matches for --unset and --replace-all

From
Thomas Rast <tr@thomasrast.ch>
Date
Nov 14, 2013, 20:24 UTC
Message-ID
<87zjp6loiz.fsf@linux-k42r.v.cablecom.net>
In-Reply-To
<20131114083747.GD16327@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 23 quoted lines
> This code is weird to follow because of the fall-throughs. I do not
> think you have introduced any bugs with your patch, but it seems weird
> to me that we set the offset at the top of the hunk. If we hit the
> conditional in the bottom half, we do actually increment storer.seen,
> but only _after_ having overwritten the value from above (with the same
> value, no less).
>
> But if we do not follow that code path, we may end up here:
>
>> @@ -1272,6 +1275,9 @@ static int store_aux(const char *key, const char *value, void *cb)
>>  			if (strrchr(key, '.') - key == store.baselen &&
>>  			      !strncmp(key, store.key, store.baselen)) {
>>  					store.state = SECTION_SEEN;
>> +					ALLOC_GROW(store.offset,
>> +						   store.seen+1,
>> +						   store.offset_alloc);
>>  					store.offset[store.seen] = cf->do_ftell(cf);
>>  			}
>>  		}
>
> where we overwrite it again, but do not update store.seen. Or we may
> trigger neither, and leave the function with our offset stored, but
> store.seen not incremented.

It's doubly strange that we write in this hunk without any protection against overflow. I was too lazy to think about it long enough to come up with a possible example that triggers this, and instead just put in the defensive ALLOC_GROW(). But if you can trigger it, it will probably cause the algorithm to go off the rails because it overwrote store.state and possibly even store.seen.

-- 
Thomas Rast
tr@thomasrast.ch
Previous: Jeff KingNext: Junio C Hamano
Message 6 of 8 in “Bug with git svn fetch? "error:too many matches for svn-remote.svn.added-placeholder"”
  1. Jess HottensteinNov 5, 2013
  2. config: arbitrary number of matches for --unset and --replace-allThomas Rast, Nov 13, 2013
  3. Eric SunshineNov 13, 2013
  4. config: arbitrary number of matches for --unset and --replace-allThomas Rast, Nov 14, 2013
  5. Jeff KingNov 14, 2013
  6. Thomas RastNov 14, 2013
  7. fixup! config: arbitrary number of matches for --unset and --replace-allJunio C Hamano, Dec 6, 2013
  8. Jeff KingDec 6, 2013

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.