system/nxinit: prevent parser from reading past string boundry

Any string ending with whitespace passed to init_parse_arguments()
could cause the parser to advance past the string boundary and read
unintended memory content.
 - " echo "A" \0& echo "B" should be parsed
   as a command with two argvs instand of five.
 - "command arg  " may lead to uncertain results.

Signed-off-by: fangpeina <fangpeina@xiaomi.com>
This commit is contained in:
fangpeina 2025-12-04 18:07:15 +08:00 committed by Xiang Xiao
parent b0fdffb7f6
commit 78bf19c83c

View file

@ -46,7 +46,7 @@ int init_parse_arguments(FAR char *buf, bool dup, int argc, FAR char **argv)
bool new = true;
int i = 0;
while (*buf != '\0')
for (; ; )
{
while (isblank(*buf))
{
@ -91,6 +91,11 @@ int init_parse_arguments(FAR char *buf, bool dup, int argc, FAR char **argv)
}
}
if (*buf == '\0')
{
break;
}
if (new)
{
argv[i++] = buf;