From 930f3a27e1c968e1e3992dfccbbc3c713163ee02 Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Tue, 31 Aug 2010 20:28:18 +0200 Subject: fixed stack pollution and parser error in shellexec plugin --- plugins/shellexec/shellexec.c | 47 ++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) (limited to 'plugins/shellexec') diff --git a/plugins/shellexec/shellexec.c b/plugins/shellexec/shellexec.c index 35c8a2eb..e8298cab 100644 --- a/plugins/shellexec/shellexec.c +++ b/plugins/shellexec/shellexec.c @@ -130,44 +130,37 @@ shx_start () strcpy (tmp, item->value); trace ("Shellexec: %s\n", tmp); - const char *command; - const char *title; - const char *name; - const char *flags; + char *args[4] = {0}; - char *semicolon; int idx = 0; - tmpptr = tmp; - do - { - semicolon = strchr (tmpptr, ':'); - if (semicolon) - *semicolon = 0; - - trace ("Shellexec: idx: %d, tmp: %s\n", idx, tmpptr); - switch (idx) - { - case 0: command = trim (tmpptr); break; - case 1: title = trim (tmpptr); break; - case 2: name = trim (tmpptr); break; - case 3: flags = trim (tmpptr); break; + char *p = tmp; + while (idx < 4 && p) { + char *e = strchr (p, ':'); + args[idx++] = p; + if (!e) { + break; } - if (semicolon) - tmpptr = semicolon + 1; - idx++; + *e = 0; + p = e+1; } - while (semicolon); if (idx < 2) { fprintf (stderr, "Shellexec: need at least command and title (%s)\n", item->value); continue; } - if (idx > 4) - { - fprintf (stderr, "Shellexec: too many parameters in configuration line (%s)\n", item->value); - continue; + + const char *command = args[0]; + const char *title = args[1]; + const char *name = args[2]; + const char *flags = args[3]; + if (!name) { + name = "noname"; + } + if (!flags) { + flags = "local"; } + if (strstr (flags, "disabled")) continue; -- cgit v1.2.3