mirror of
https://github.com/git/git.git
synced 2026-01-25 18:12:44 +00:00
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>
This commit is contained in:
@@ -135,6 +135,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);
|
||||
|
||||
Reference in New Issue
Block a user