From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH] utf8.c: fix strbuf_utf8_replace copying the last NUL to dst string
Date: Tue, 29 Jul 2014 20:10:29 +0700 [thread overview]
Message-ID: <1406639429-28748-1-git-send-email-pclouds@gmail.com> (raw)
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 reply other threads:[~2014-07-29 13:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-29 13:10 Nguyễn Thái Ngọc Duy [this message]
2014-07-29 19:56 ` [PATCH] utf8.c: fix strbuf_utf8_replace copying the last NUL to dst string Junio C Hamano
2014-07-30 10:20 ` Duy Nguyen
2014-07-30 18:23 ` Junio C Hamano
2014-08-10 7:05 ` [PATCH v2] utf8.c: fix strbuf_utf8_replace() consuming data beyond input string Nguyễn Thái Ngọc Duy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1406639429-28748-1-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).