acrnboot: fix the parsing hv_cmdline to correctly handle the case of containing trailing whitespaces

The pointer variable 'start' should be checked against NULL
    right after detected it is not pointer to a space character,
    otherwise the pointer variable 'end' must hold the wrong
    address right after NULL if the cmdline containing trailing
    whitespaces and deference the wrong address out of cmdline
    string. this parsing code also been optimized and simplified.

Tracked-On: projectacrn#4250
Signed-off-by: Gary <gordon.king@intel.com>
This commit is contained in:
Gary 2019-12-13 11:59:14 -08:00 committed by wenlingz
parent 5f9d1379bc
commit 5b5f1735ff
1 changed files with 12 additions and 12 deletions

View File

@ -17,7 +17,7 @@
int32_t parse_hv_cmdline(void) int32_t parse_hv_cmdline(void)
{ {
const char *start; const char *start;
const char *end; const char *end = NULL;
struct multiboot_info *mbi = NULL; struct multiboot_info *mbi = NULL;
if (boot_regs[0] != MULTIBOOT_INFO_MAGIC) { if (boot_regs[0] != MULTIBOOT_INFO_MAGIC) {
@ -35,20 +35,20 @@ int32_t parse_hv_cmdline(void)
start = (char *)hpa2hva_early((uint64_t)mbi->mi_cmdline); start = (char *)hpa2hva_early((uint64_t)mbi->mi_cmdline);
dev_dbg(ACRN_DBG_PARSE, "hv cmdline: %s", start); dev_dbg(ACRN_DBG_PARSE, "hv cmdline: %s", start);
do { while ((start != NULL) && ((*start) != '\0')) {
while (*start == ' ') while ((*start) == ' ')
start++; start++;
if ((*start) != '\0') {
end = start + 1;
while ((*end != ' ') && ((*end) != '\0'))
end++;
end = start + 1; if (!handle_dbg_cmd(start, (int32_t)(end - start))) {
while ((*end != ' ') && ((*end) != '\0')) /* if not handled by handle_dbg_cmd, it can be handled further */
end++; }
start = end;
if (!handle_dbg_cmd(start, (int32_t)(end - start))) {
/* if not handled by handle_dbg_cmd, it can be handled further */
} }
start = end + 1; }
} while (((*end) != '\0') && ((*start) != '\0'));
return 0; return 0;
} }