security: fix issues reported by Klocwork

- NULL pointer reference risk
 - buffer overflow risk

Signed-off-by: Yonghua Huang <yonghua.huang@intel.com>
This commit is contained in:
Yonghua Huang
2018-05-03 19:28:17 +08:00
committed by lijinxia
parent 02f993ca02
commit 6de10d6908
3 changed files with 31 additions and 6 deletions

View File

@@ -460,7 +460,7 @@ int shell_cmd_help(struct shell *p_shell,
/* Calculate spaces needed for alignment */
spaces = MAX_INDENT_LEN - strnlen_s(p_cmd->str,
MAX_INDENT_LEN) + 1;
MAX_INDENT_LEN - 1);
space_buf[spaces] = '\0';
shell_puts(p_shell, space_buf);
@@ -913,6 +913,9 @@ int shell_show_cpu_int(struct shell *p_shell,
{
char *temp_str = alloc_page();
if (temp_str == NULL)
return -ENOMEM;
get_cpu_interrupt_info(temp_str, CPU_PAGE_SIZE);
shell_puts(p_shell, temp_str);
@@ -926,6 +929,9 @@ int shell_show_ptdev_info(struct shell *p_shell,
{
char *temp_str = alloc_page();
if (temp_str == NULL)
return -ENOMEM;
get_ptdev_info(temp_str, CPU_PAGE_SIZE);
shell_puts(p_shell, temp_str);
@@ -939,6 +945,9 @@ int shell_show_req_info(struct shell *p_shell,
{
char *temp_str = alloc_page();
if (temp_str == NULL)
return -ENOMEM;
get_req_info(temp_str, CPU_PAGE_SIZE);
shell_puts(p_shell, temp_str);
@@ -952,6 +961,9 @@ int shell_show_vioapic_info(struct shell *p_shell, int argc, char **argv)
char *temp_str = alloc_page();
uint32_t vmid;
if (temp_str == NULL)
return -ENOMEM;
/* User input invalidation */
if (argc != 2) {
snprintf(temp_str, CPU_PAGE_SIZE, "\r\nvmid param needed\r\n");
@@ -972,6 +984,9 @@ int shell_show_ioapic_info(struct shell *p_shell,
{
char *temp_str = alloc_pages(2);
if (temp_str == NULL)
return -ENOMEM;
get_ioapic_info(temp_str, 2 * CPU_PAGE_SIZE);
shell_puts(p_shell, temp_str);
@@ -985,6 +1000,9 @@ int shell_show_vmexit_profile(struct shell *p_shell,
{
char *temp_str = alloc_pages(2);
if (temp_str == NULL)
return -ENOMEM;
get_vmexit_profile(temp_str, 2*CPU_PAGE_SIZE);
shell_puts(p_shell, temp_str);