Re: [PATCH] apply: use strcmp(3) for comparing strings in gitdiff_verify_name()
- From
René Scharfe <l.s.r@web.de>
- Date
- Jul 9, 2017, 12:20 UTC
- Message-ID
- <df3bd047-6ddd-c120-54dd-4165d2257bb0@web.de>
- In-Reply-To
- <87o9svgia8.fsf@linux-m68k.org>
Am 08.07.2017 um 15:38 schrieb Andreas Schwab:
Show 15 quoted lines
> On Jul 08 2017, René Scharfe <l.s.r@web.de> wrote: > >> Am 08.07.2017 um 13:08 schrieb Andreas Schwab: >>> 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? > > Sorry, I misremembered. It's only memchr that has this restriction.
Hmm, I can't get ASan to complain about memchr reading beyond the end of a C string, but I don't know why. Glibc reads full words [1], and I don't see how the standard [2] forbids reading past the found byte.
René
[1] https://sourceware.org/git/?p=glibc.git;a=blob;f=string/memchr.c [2] http://pubs.opengroup.org/onlinepubs/009695399/functions/memchr.html