Re: [PATCH] pkt-line: don't check string length in packet_length()
- From
René Scharfe <l.s.r@web.de>
- Date
- Jul 6, 2023, 05:07 UTC
- Message-ID
- <a5acfab5-0133-b3d6-3efc-c3f107e78b58@web.de>
- In-Reply-To
- <xmqqsfa2uh83.fsf@gitster.g>
Am 06.07.23 um 00:27 schrieb Junio C Hamano:
Show 7 quoted lines
> hex.h:hex2chr() says "don't run over the end of short strings", but > as far as I can see it does not check any such thing; find a page of > memory, whose next page is unmapped, and pointing *s at the last > byte of that page and calling it will happily run over the end and > would cause SIGBUS. The function assumes that such a short string > is always NUL terminated, which is not a great way to guarantee that > we do not run over the end of strings.
Yes, hex2chr() works with C strings, i.e. those that end with a NUL character. An empty string is just a NUL byte, a string of length 1 is a non-NUL byte and a NUL. The function reads one byte from the former and otherwise two bytes -- no overrun.
If a C string loses its NUL, how could you detect its end?
René