1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-22 16:03:03 +01:00

Use a small hack to get around an ncurses buffer overread

Patch by iphydf
This commit is contained in:
jfreegman 2022-03-16 16:31:41 -04:00
parent fdfaaf953f
commit 22ca3704d2
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63

View File

@ -143,11 +143,14 @@ static struct line_info *line_info_ret_queue(struct history *hst)
*/ */
static int print_n_chars(WINDOW *win, const wchar_t *s, size_t n, int max_y) static int print_n_chars(WINDOW *win, const wchar_t *s, size_t n, int max_y)
{ {
// we use an array to represent a single wchar in order to get around an ncurses
// bug with waddnwstr() that overreads the memory address by one byte when
// supplied with a single wchar.
wchar_t ch[2] = {0};
bool newline = false; bool newline = false;
wchar_t ch;
for (size_t i = 0; i < n && (ch = s[i]); ++i) { for (size_t i = 0; i < n && (ch[0] = s[i]); ++i) {
if (ch == L'\n') { if (ch[0] == L'\n') {
newline = true; newline = true;
int x; int x;
@ -164,11 +167,11 @@ static int print_n_chars(WINDOW *win, const wchar_t *s, size_t n, int max_y)
if (win) { if (win) {
#ifdef HAVE_WIDECHAR #ifdef HAVE_WIDECHAR
waddnwstr(win, &ch, 1); waddnwstr(win, ch, 1);
#else #else
char b; char b;
if (wcstombs(&b, &ch, sizeof(char)) != 1) { if (wcstombs(&b, ch, sizeof(char)) != 1) {
continue; continue;
} }