zipl/boot: Fix the bounds check in the command line processing

By design, before replacement of '${FOO}' with its value, the
procedure checks that the resulted command line doesn't exceed the
maximum one.
The old check used the never updated length of the original command
line, which is incorrect. Instead, use its current length resulting
from the replacement happened at the previous iteration.

Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Eduard Shishkin
2026-07-15 11:31:13 +02:00
committed by Jan Höppner
parent a8a87779c0
commit 9ce9ed72a9
+6 -1
View File
@@ -292,7 +292,8 @@ void process_parm_line(struct env_hash_entry **buckets, unsigned int cmdl_len,
*/
len = strlen(val);
if (cmdl_len + len - (end - start + 1) >= max_len)
if ((cmdl_end - (char *)COMMAND_LINE) + len -
(end - start + 1) >= max_len)
/* VALUE doesn't fit */
break;
/*
@@ -309,6 +310,10 @@ void process_parm_line(struct env_hash_entry **buckets, unsigned int cmdl_len,
start += len;
}
if (cmdl_len > cmdl_end - (char *)COMMAND_LINE)
/*
* the resulted command line is shorter than the
* original one. Erase the garbage at the end
*/
memset(cmdl_end, 0,
cmdl_len - (cmdl_end - (char *)COMMAND_LINE));
}