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

Re: [PATCH] wt-status: Don't find scissors line beyond buf len

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 7, 2024, 19:35 UTC
Message-ID
<xmqqsf11ltrt.fsf@gitster.g>
In-Reply-To
<20240307183743.219951-1-flosch@nutanix.com>
Florian Schmidt <flosch@nutanix.com> writes:
> Side remark: Since strstr() doesn't consider len, and will always search
> up to a null byte, I now wonder whether it would be safer to create a
> new strbuf that only contains the len bytes we want to operate on.

That is a valid concern in general, but does not seem to apply to the current codebase. Thanks for being careful.

Two of the three callers of wt_status_locate_end() feed the pointer into a piece of memory that is owned by strbuf, which guarantees that the memory has an extra NUL to terminate it as a string even if you did

	strbuf buf = STRBUF_INIT;
	strbuf_addch(&buf, 'A');

The other one is in commit.c:ignored_log_message_bytes() that still takes <buf, len> as input, but again, two of its three callers call it with a pointer that points at the beginning of memory held by an instance of strbuf.

That leaves us trailer.c:find_end_of_log_message() the only one to worry about, but it uses strlen() on the pointer before calling ignored_log_message_bytes() so the region of the memory pointed at by the pointer is assumed to be NUL-terminated already, and presumably (I didn't follow the logic there too closely) the length is also computed within that NUL-terminated string.

Previous: Linus ArverNext: Florian Schmidt
Message 13 of 14 in “wt-status: Don't find scissors line beyond buf len”
  1. wt-status: Don't find scissors line beyond buf lenFlorian Schmidt, Mar 7, 2024
  2. Junio C HamanoMar 7, 2024
  3. Junio C HamanoMar 7, 2024
  4. Eric SunshineMar 7, 2024
  5. Kristoffer HaugsbakkMar 7, 2024
  6. Junio C HamanoMar 7, 2024
  7. Eric SunshineMar 7, 2024
  8. Kristoffer HaugsbakkMar 7, 2024
  9. Florian SchmidtMar 8, 2024
  10. Junio C HamanoMar 8, 2024
  11. Florian SchmidtMar 8, 2024
  12. Linus ArverApr 6, 2024
  13. Junio C HamanoMar 7, 2024
  14. Florian SchmidtMar 8, 2024

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.