From 18f1730b920f2008100356744dd4786583ec7664 Mon Sep 17 00:00:00 2001 From: Hendrik Brueckner Date: Thu, 24 Aug 2017 14:14:07 +0200 Subject: [PATCH] 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 Signed-off-by: Michael Holzheu --- zkey/zkey.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zkey/zkey.c b/zkey/zkey.c index d2736a69..57770a78 100644 --- a/zkey/zkey.c +++ b/zkey/zkey.c @@ -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;