[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Fix buffer overflow when too long a command is typed
From: |
John Darrington |
Subject: |
[PATCH] Fix buffer overflow when too long a command is typed |
Date: |
Sat, 21 Mar 2020 12:43:29 +0100 |
---
src/pk-cmd.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/src/pk-cmd.c b/src/pk-cmd.c
index dde7cf2c..a5378b0b 100644
--- a/src/pk-cmd.c
+++ b/src/pk-cmd.c
@@ -292,9 +292,16 @@ pk_cmd_exec_1 (char *str, struct pk_trie *cmds_trie, char
*prefix)
/* Get the command name. */
i = 0;
+ memset (cmd_name, 0, MAX_CMD_NAME);
while (isalnum (*p) || *p == '_' || *p == '-' || *p == ':')
- cmd_name[i++] = *(p++);
- cmd_name[i] = '\0';
+ {
+ if (i >= MAX_CMD_NAME - 1)
+ {
+ pk_printf (_("%s: command not found.\n"), cmd_name);
+ return 0;
+ }
+ cmd_name[i++] = *(p++);
+ }
/* Look for the command in the prefix table. */
cmd = pk_trie_get_cmd (cmds_trie, cmd_name);
--
2.20.1