Skip to content

Commit 1764e81

Browse files
committed
Merge branch 'nd/strbuf-utf8-replace'
* nd/strbuf-utf8-replace: utf8.c: fix strbuf_utf8_replace() consuming data beyond input string
2 parents 27fbcf8 + 4308759 commit 1764e81

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

t/t4205-log-pretty-formats.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,13 @@ EOF
431431
test_cmp expected actual
432432
'
433433

434+
test_expect_success 'strbuf_utf8_replace() not producing NUL' '
435+
git log --color --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)%C(auto)%d" |
436+
test_decode_color |
437+
nul_to_q >actual &&
438+
! grep Q actual
439+
'
440+
434441
# get new digests (with no abbreviations)
435442
head1=$(git rev-parse --verify HEAD~0) &&
436443
head2=$(git rev-parse --verify HEAD~1) &&

utf8.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,9 @@ void strbuf_utf8_replace(struct strbuf *sb_src, int pos, int width,
382382
dst += n;
383383
}
384384

385+
if (src >= end)
386+
break;
387+
385388
old = src;
386389
n = utf8_width((const char**)&src, NULL);
387390
if (!src) /* broken utf-8, do nothing */

0 commit comments

Comments
 (0)