1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 09:27:59 +00:00

Fix buffer overrun on keypress in non-UTF-8 sessions.

Commit 71e42b04a's refactoring of terminal keyboard input, in the case
where a Unicode string derived from a keystroke is translated into
some other charset to put on the wire, had allocated the output buffer
for that translation one byte too small.
This commit is contained in:
Simon Tatham 2019-07-02 21:22:01 +01:00
parent e790adec4a
commit 54cd853a49

View File

@ -2991,11 +2991,13 @@ static strbuf *term_input_data_from_unicode(
* Since the terminal doesn't currently support any multibyte
* character set other than UTF-8, we can assume here that
* there will be at most one output byte per input wchar_t.
* (But also we must allow space for the trailing NUL that
* wc_to_mb will write.)
*/
char *bufptr = strbuf_append(buf, len);
char *bufptr = strbuf_append(buf, len + 1);
int rv;
rv = wc_to_mb(term->ucsdata->line_codepage, 0, widebuf, len,
bufptr, len, NULL, term->ucsdata);
bufptr, len + 1, NULL, term->ucsdata);
buf->len = rv < 0 ? 0 : rv;
}