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

Re: [PATCH] apply: use strcmp(3) for comparing strings in gitdiff_verify_name()

From
René Scharfe <l.s.r@web.de>
Date
Jul 8, 2017, 11:43 UTC
Message-ID
<e46a7de9-3e0e-4eeb-c9a3-a8b5f22620b4@web.de>
In-Reply-To
<87tw2ngp94.fsf@linux-m68k.org>
Am 08.07.2017 um 13:08 schrieb Andreas Schwab:
Show 8 quoted lines
> On Jul 08 2017, René Scharfe <l.s.r@web.de> wrote:
> 
>> Avoid running over the end of another -- a C string whose length we
>> don't know -- by using strcmp(3) instead of memcmp(3) for comparing it
>> with another C string.
> 
> That's not a good justification for the change, since memcmp never reads
> past the differing characters.
Interesting.  Where does that guarantee come from?

ASan reports an overflow with the following test program for me on Debian testing x64:

#include <string.h>
int main(int argc, char **argv)
{
         char a[32] = "1234567890123456789012345678901";
         char b[2] = "a";
         return memcmp(a, b, 32);
}
Previous: Andreas SchwabNext: Andreas Schwab
Message 3 of 12 in “apply: use strcmp(3) for comparing strings in gitdiff_verify_name()”
  1. apply: use strcmp(3) for comparing strings in gitdiff_verify_name()René Scharfe, Jul 8, 2017
  2. Andreas SchwabJul 8, 2017
  3. René ScharfeJul 8, 2017
  4. Andreas SchwabJul 8, 2017
  5. René ScharfeJul 9, 2017
  6. Andreas SchwabJul 9, 2017
  7. René ScharfeJul 9, 2017
  8. Junio C HamanoJul 9, 2017
  9. Ramsay JonesJul 8, 2017
  10. René ScharfeJul 8, 2017
  11. Junio C HamanoJul 8, 2017
  12. René ScharfeJul 9, 2017

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.