Enlightenment CVS committal Author : andyetitmoves Project : e17 Module : libs/ecore
Dir : e17/libs/ecore/src/lib/ecore Modified Files: ecore_exe.c Log Message: Attempt to speed up ecore_exe_run by seeing if there are any shell metacharacters present in the command line passed. If there aren't any, parse command line to arguments and pass to execvp instead of calling `sh -c' with the entire command line. Hope we have covered all cases in which sh -c should be necessarily invoked :) The current approach is pretty conservative though - anything suspicious, and over to sh. =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore/ecore_exe.c,v retrieving revision 1.18 retrieving revision 1.19 diff -u -3 -r1.18 -r1.19 --- ecore_exe.c 9 Nov 2005 20:01:32 -0000 1.18 +++ ecore_exe.c 29 Nov 2005 12:39:09 -0000 1.19 @@ -34,7 +34,7 @@ pid_t pid; if (!exe_cmd) return NULL; - pid = fork(); + pid = fork(); if (pid) { exe = calloc(1, sizeof(Ecore_Exe)); @@ -49,8 +49,66 @@ exes = _ecore_list2_append(exes, exe); return exe; } - setsid(); - execl("/bin/sh", "/bin/sh", "-c", exe_cmd, (char *)NULL); + { + char use_sh = 1; + char* buf = NULL; + char** args = NULL; + if (! strpbrk(exe_cmd, "|&;<>()$`\\\"'*?#")) + { + if (! (buf = strdup(exe_cmd))) + return NULL; + char* token = strtok(buf, " \t\n\v"); + char pre_command = 1; + int num_tokens = 0; + while(token) + { + if (token[0] == '~') + break; + if (pre_command) + { + if (token[0] == '[') + break; + if (strchr(token, '=')) + break; + else + pre_command = 0; + } + num_tokens ++; + token = strtok(NULL, " \t\n\v"); + } + free(buf); + buf = NULL; + if (! token && num_tokens) + { + int i = 0; + char* token; + if (! (buf = strdup(exe_cmd))) + return NULL; + token = strtok(buf, " \t\n\v"); + use_sh = 0; + if (! (args = (char**) calloc(num_tokens + 1, sizeof(char*)))) { + free (buf); + return NULL; + } + for (i = 0; i < num_tokens; i ++) + { + if (token) + args[i] = token; + token = strtok(NULL, " \t\n\v"); + } + args[num_tokens] = NULL; + } + } + setsid(); + if (use_sh) + execl("/bin/sh", "/bin/sh", "-c", exe_cmd, (char *)NULL); + else + execvp(args[0], args); + if (buf) + free(buf); + if(args) + free(args); + } exit(127); return NULL; } ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs