summaryrefslogtreecommitdiff
path: root/compat
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2017-05-04 13:55:34 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-05-08 03:18:19 (GMT)
commitb6b066adf9e1e970a6d8295db630ab1e1f3bc71c (patch)
treecb406803715e04953a1745fbb26f8c1f85d672ff /compat
parent3057da5ad51b3256a6f6b94d034e6a5571ce5ece (diff)
downloadgit-b6b066adf9e1e970a6d8295db630ab1e1f3bc71c.zip
git-b6b066adf9e1e970a6d8295db630ab1e1f3bc71c.tar.gz
git-b6b066adf9e1e970a6d8295db630ab1e1f3bc71c.tar.bz2
winansi: avoid buffer overrun
When we could not convert the UTF-8 sequence into Unicode for writing to the Console, we should not try to write an insanely-long sequence of invalid wide characters (mistaking the negative return value for an unsigned length). Reported by Coverity. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'compat')
-rw-r--r--compat/winansi.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/compat/winansi.c b/compat/winansi.c
index a551de9..a11a0f1 100644
--- a/compat/winansi.c
+++ b/compat/winansi.c
@@ -140,6 +140,11 @@ static void write_console(unsigned char *str, size_t len)
/* convert utf-8 to utf-16 */
int wlen = xutftowcsn(wbuf, (char*) str, ARRAY_SIZE(wbuf), len);
+ if (wlen < 0) {
+ wchar_t *err = L"[invalid]";
+ WriteConsoleW(console, err, wcslen(err), &dummy, NULL);
+ return;
+ }
/* write directly to console */
WriteConsoleW(console, wbuf, wlen, &dummy, NULL);