zipl/stage3: fix buffer overflow

The inserted blank must also be taken into account for the calculation
of `cmdline_len`. In general it's only possible to insert a blank if
the command line length is not already the maximum.

Reviewed-by: Philipp Rudo <prudo@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Marc Hartmayer
2020-03-31 11:20:27 +02:00
committed by Jan Höppner
parent 9a68a25ab6
commit 4eea67cd6f
+4 -4
View File
@@ -201,13 +201,13 @@ void start(void)
*/ */
if (*cextra == 0x3d) { if (*cextra == 0x3d) {
memcpy(cmdline, cextra, cextra_len); memcpy(cmdline, cextra, cextra_len);
} else { } else if (cmdline_len + 1 <= COMMAND_LINE_SIZE - 1) {
/* check if length is within max value */
cextra_len = (cmdline_len + 1 + cextra_len <= COMMAND_LINE_SIZE) ?
cextra_len : (COMMAND_LINE_SIZE - cmdline_len - 1);
/* add blank */ /* add blank */
cmdline[cmdline_len] = 0x20; cmdline[cmdline_len] = 0x20;
cmdline_len++; cmdline_len++;
/* check if length is within max value */
cextra_len = (cmdline_len + cextra_len <= COMMAND_LINE_SIZE - 1) ?
cextra_len : (COMMAND_LINE_SIZE - 1 - cmdline_len);
/* append string */ /* append string */
memcpy(cmdline + cmdline_len, cextra, cextra_len); memcpy(cmdline + cmdline_len, cextra, cextra_len);
/* terminate 0 */ /* terminate 0 */