Jude Rich has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/38140 )
Change subject: util/kconfig/nconf.c: Use strnlen vs. strlen and int vs. size_t ......................................................................
util/kconfig/nconf.c: Use strnlen vs. strlen and int vs. size_t
strnlen helps prevent errors from no null termination. Also, sizeof/strnlen both return size_t, so we should use that rather than int. Additionally, formatting has been changed to fit with the rest of the file.
Signed-off-by: Jude A Rich juder11@gmail.com Change-Id: I1c62b119bfd9953a7296ccd058d562c35cc9c75f --- M util/kconfig/nconf.c 1 file changed, 8 insertions(+), 5 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/40/38140/1
diff --git a/util/kconfig/nconf.c b/util/kconfig/nconf.c index 4181c41..afbeb52 100644 --- a/util/kconfig/nconf.c +++ b/util/kconfig/nconf.c @@ -567,14 +567,16 @@ va_list ap; char *append_ptr; /* pointer to the free space in the target string */ int index = items_num-1; /* index of item to append string */ - int kmi_str_len; /* length of initial string */ - int str_space; /* length of unused space in string */ + size_t kmi_str_len; /* length of initial string */ + size_t str_space; /* length of unused space in string */
/* return if there's no item to work with */ if (index < 0) return;
- kmi_str_len = strlen(k_menu_items[index].str); + kmi_str_len = strnlen( + k_menu_items[index].str, + sizeof(k_menu_items[index].str)); str_space = sizeof(k_menu_items[index].str) - kmi_str_len; append_ptr = k_menu_items[index].str + kmi_str_len;
@@ -585,8 +587,9 @@
/* set menu item to new item string */ free_item(curses_menu_items[index]); - curses_menu_items[index] = new_item(k_menu_items[index].str, - k_menu_items[index].str); + curses_menu_items[index] = new_item( + k_menu_items[index].str, + k_menu_items[index].str); set_item_userptr(curses_menu_items[index], &k_menu_items[index]); }