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

[PATCH] utf8.c: fix strbuf_utf8_replace copying the last NUL to dst string

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jul 29, 2014, 13:10 UTC
Message-ID
<1406639429-28748-1-git-send-email-pclouds@gmail.com>

When utf8_width(&src) is called with *src == NULL (because the source string ends with an ansi sequence), it returns 0 and steps 'src' by one. This stepping makes strbuf_utf8_replace add NUL to the destination string at the end of the loop. Check and break the loop early.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 utf8.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/utf8.c b/utf8.c
index b30790d..cd090a1 100644
--- a/utf8.c
+++ b/utf8.c
@@ -381,6 +381,8 @@ void strbuf_utf8_replace(struct strbuf *sb_src, int pos, int width,
 			src += n;
 			dst += n;
 		}
+		if (src >= end)
+			break;
 
 		old = src;
 		n = utf8_width((const char**)&src, NULL);
-- 
2.1.0.rc0.66.gb9187ad
Next: Junio C Hamano
Message 1 of 5 in “utf8.c: fix strbuf_utf8_replace copying the last NUL to dst string”
  1. utf8.c: fix strbuf_utf8_replace copying the last NUL to dst stringNguyễn Thái Ngọc Duy, Jul 29, 2014
  2. Junio C HamanoJul 29, 2014
  3. Duy NguyenJul 30, 2014
  4. Junio C HamanoJul 30, 2014
  5. utf8.c: fix strbuf_utf8_replace() consuming data beyond input stringNguyễn Thái Ngọc Duy, Aug 10, 2014

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.