zkey: correctly detect abbreviated commands

Abbreviated commands are not recognized and zkey issues an invalid
command error.

In is_command(), the abbreviated command string is copied into the
command_str variable.  Because this variable is not initialized and,
thus, might contain arbitrary data, a NUL-terminated is not guaranteed.
The following string comparison is very likely to fail.  Correct this
problem by comparing up to the length of the command string only.

Signed-off-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
This commit is contained in:
Hendrik Brueckner
2017-08-24 14:14:07 +02:00
committed by Michael Holzheu
parent f1a5ab20b7
commit 18f1730b92

View File

@@ -964,7 +964,7 @@ static bool is_command(struct zkey_command *command, const char *str)
if (str_len > strlen(command->command))
return false;
strncpy(command_str, command->command, str_len);
if (strcasecmp(str, command_str) != 0)
if (strncasecmp(str, command_str, str_len) != 0)
return false;
return true;