From 802f7d7523f649258368db37eb2eaf8653d135f7 Mon Sep 17 00:00:00 2001 From: Tsarevich Dmitry Date: Sun, 23 Feb 2020 21:19:03 +0300 Subject: [PATCH] [buf] Ensure section name do not overflow buffer IFF section name will become 127+ symbols length, overflow of buffer is possible. Ensure buffer is always zero-terminated and no overrun occured. --- src/ui.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ui.c b/src/ui.c index 0eb43f69..2900f42d 100644 --- a/src/ui.c +++ b/src/ui.c @@ -563,8 +563,11 @@ void SetSectionHeaders(HWND hDlg) memset(wtmp, 0, sizeof(wtmp)); GetWindowTextW(hCtrl, wtmp, ARRAYSIZE(wtmp)); wlen = wcslen(wtmp); - wtmp[wlen++] = L' '; - wtmp[wlen++] = L' '; + if (wlen < ARRAYSIZE(wtmp) - 1) + wtmp[wlen++] = L' '; + if (wlen < ARRAYSIZE(wtmp) - 1) + wtmp[wlen++] = L' '; + wtmp[ARRAYSIZE(wtmp) - 1] = L'\0'; SetWindowTextW(hCtrl, wtmp); GetWindowRect(hCtrl, &rc); MapWindowPoints(NULL, hDlg, (POINT*)&rc, 2);