[PATCH] lxdialog: checklist: Add malloc allocation judgment

From: Li zeming
Date: Mon Oct 24 2022 - 01:42:51 EST


Add list_item Only when the pointer judges that the pointer is valid
can function code be executed.

Signed-off-by: Li zeming <zeming@xxxxxxxxxxxx>
---
scripts/kconfig/lxdialog/checklist.c | 45 ++++++++++++++--------------
1 file changed, 23 insertions(+), 22 deletions(-)

diff --git a/scripts/kconfig/lxdialog/checklist.c b/scripts/kconfig/lxdialog/checklist.c
index fd161cfff121..61a8f86fe467 100644
--- a/scripts/kconfig/lxdialog/checklist.c
+++ b/scripts/kconfig/lxdialog/checklist.c
@@ -19,29 +19,30 @@ static void print_item(WINDOW * win, int choice, int selected)
{
int i;
char *list_item = malloc(list_width + 1);
+ if (list_item) {
+ strncpy(list_item, item_str(), list_width - item_x);
+ list_item[list_width - item_x] = '\0';

- strncpy(list_item, item_str(), list_width - item_x);
- list_item[list_width - item_x] = '\0';
-
- /* Clear 'residue' of last item */
- wattrset(win, dlg.menubox.atr);
- wmove(win, choice, 0);
- for (i = 0; i < list_width; i++)
- waddch(win, ' ');
-
- wmove(win, choice, check_x);
- wattrset(win, selected ? dlg.check_selected.atr
- : dlg.check.atr);
- if (!item_is_tag(':'))
- wprintw(win, "(%c)", item_is_tag('X') ? 'X' : ' ');
-
- wattrset(win, selected ? dlg.tag_selected.atr : dlg.tag.atr);
- mvwaddch(win, choice, item_x, list_item[0]);
- wattrset(win, selected ? dlg.item_selected.atr : dlg.item.atr);
- waddstr(win, list_item + 1);
- if (selected) {
- wmove(win, choice, check_x + 1);
- wrefresh(win);
+ /* Clear 'residue' of last item */
+ wattrset(win, dlg.menubox.atr);
+ wmove(win, choice, 0);
+ for (i = 0; i < list_width; i++)
+ waddch(win, ' ');
+
+ wmove(win, choice, check_x);
+ wattrset(win, selected ? dlg.check_selected.atr
+ : dlg.check.atr);
+ if (!item_is_tag(':'))
+ wprintw(win, "(%c)", item_is_tag('X') ? 'X' : ' ');
+
+ wattrset(win, selected ? dlg.tag_selected.atr : dlg.tag.atr);
+ mvwaddch(win, choice, item_x, list_item[0]);
+ wattrset(win, selected ? dlg.item_selected.atr : dlg.item.atr);
+ waddstr(win, list_item + 1);
+ if (selected) {
+ wmove(win, choice, check_x + 1);
+ wrefresh(win);
+ }
}
free(list_item);
}
--
2.18.2