]> git.tue.mpg.de Git - paraslash.git/commitdiff
gui: Simplify handle_command() and avoid a buffer overflow.
authorAndre Noll <maan@systemlinux.org>
Sun, 4 Apr 2010 22:08:34 +0000 (00:08 +0200)
committerAndre Noll <maan@systemlinux.org>
Sun, 4 Apr 2010 22:08:34 +0000 (00:08 +0200)
It's not save to use strcpy() here.

gui.c

diff --git a/gui.c b/gui.c
index 5b44819c05afc074fadca3a5a7d5c1ece9fe8b8f..8272fee79747847522ebf7282d071b52fb66f845 100644 (file)
--- a/gui.c
+++ b/gui.c
@@ -1348,31 +1348,29 @@ static void handle_command(int c)
 
        /* first check user's key bindings */
        for (i = 0; i < conf.key_map_given; ++i) {
-               char tmp[MAXLINE], *handler, *arg;
+               char *tmp, *handler, *arg;
 
-               strcpy(tmp, conf.key_map_arg[i]);
-               if (!split_key_map(tmp, &handler, &arg))
+               tmp = para_strdup(conf.key_map_arg[i]);
+               if (!split_key_map(tmp, &handler, &arg)) {
+                       free(tmp);
                        return;
-               if (!strcmp(tmp, km_keyname(c))) {
-                       if (*handler == 'd') {
-                               display_cmd(arg);
-                               return;
-                       }
-                       if (*handler == 'x') {
-                               external_cmd(arg);
-                               return;
-                       }
-                       if (*handler == 'p') {
-                               client_cmd_cmdline(arg);
-                               return;
-                       }
-                       if (*handler == 'i') {
-                               int num = find_cmd_byname(arg);
-                               if (num >= 0)
-                                       command_list[num].handler();
-                               return;
-                       }
                }
+               if (strcmp(tmp, km_keyname(c))) {
+                       free(tmp);
+                       continue;
+               }
+               if (*handler == 'd')
+                       display_cmd(arg);
+               else if (*handler == 'x')
+                       external_cmd(arg);
+               else if (*handler == 'p')
+                       client_cmd_cmdline(arg);
+               else if (*handler == 'i') {
+                       int num = find_cmd_byname(arg);
+                       if (num >= 0)
+                               command_list[num].handler();
+               }
+               free(tmp);
        }
        /* not found, check internal key bindings */
        for (i = 0; command_list[i].handler; i++) {