mirror of
https://github.com/lc-soft/LCUI.git
synced 2026-11-30 16:48:21 +01:00
fix(widgets): fix password mask buffer overflow
- allocate room for the terminating wide character when masking text blocks - add a regression that enables password masking before entering text
This commit is contained in:
@@ -296,7 +296,7 @@ static void textinput_process_textblock(ui_widget_t *widget,
|
||||
break;
|
||||
}
|
||||
if (edit->password_char && txtblk->owner == TEXTBLOCK_OWNER_SOURCE) {
|
||||
wchar_t *text = malloc(sizeof(wchar_t) * txtblk->length + 1);
|
||||
wchar_t *text = malloc(sizeof(wchar_t) * (txtblk->length + 1));
|
||||
wcsncpy(text, txtblk->text, txtblk->length + 1);
|
||||
fillchar(text, edit->password_char);
|
||||
layer = edit->layer_mask;
|
||||
|
||||
@@ -12,6 +12,34 @@
|
||||
#include <LCUI.h>
|
||||
#include <ctest-custom.h>
|
||||
|
||||
static void check_password_input(void)
|
||||
{
|
||||
ui_widget_t *w = ui_create_widget("textinput");
|
||||
wchar_t wcs[64];
|
||||
|
||||
ui_textinput_set_password_char(w, L'*');
|
||||
ui_textinput_set_text_w(w, L"secret");
|
||||
ui_widget_update(w);
|
||||
|
||||
ctest_equal_bool("password input should keep the text length",
|
||||
ui_textinput_get_text_length(w) == 6, true);
|
||||
ctest_equal_bool("password input should preserve the underlying text",
|
||||
ui_textinput_get_text_w(w, 0, 64, wcs) == 6 &&
|
||||
wcscmp(wcs, L"secret") == 0,
|
||||
true);
|
||||
|
||||
ui_textinput_set_password_char(w, 0);
|
||||
ui_widget_update(w);
|
||||
ctest_equal_bool(
|
||||
"disabling password masking should restore the plain text",
|
||||
ui_textinput_get_text_w(w, 0, 64, wcs) == 6 &&
|
||||
wcscmp(wcs, L"secret") == 0,
|
||||
true);
|
||||
|
||||
ui_widget_destroy(w);
|
||||
ui_clear_trash();
|
||||
}
|
||||
|
||||
static void check_multiline_attr(void)
|
||||
{
|
||||
ui_widget_t *single = ui_create_widget("textinput");
|
||||
@@ -100,6 +128,7 @@ void test_textinput(void)
|
||||
ctest_equal_bool("should retrieve identical inserted wide string",
|
||||
wcscmp(L"hello, world!", wcs) == 0, true);
|
||||
ui_widget_destroy(w);
|
||||
check_password_input();
|
||||
check_multiline_attr();
|
||||
lcui_destroy();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user