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:
parent
5f9d1379bc
commit
5b5f1735ff
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue