From 20b33308626a861f6432e627c2983e63706588ce Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 9 Jun 2009 15:59:38 +0200 Subject: [PATCH] spawn: fix crash with command starting with white space Signed-off-by: Julien Danjou --- spawn.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spawn.c b/spawn.c index e7a7cb7b..e3a31a4d 100644 --- a/spawn.c +++ b/spawn.c @@ -279,7 +279,12 @@ luaA_spawn(lua_State *L) if(use_sn) { char *cmdname, *space; - if((space = strchr(cmd, ' '))) + const char *first_no_space_char = cmd; + /* Look for the first char which is not space */ + while(*first_no_space_char && *first_no_space_char == ' ') + first_no_space_char++; + /* Look for space in the string to get the command name. */ + if((space = strchr(first_no_space_char, ' '))) cmdname = a_strndup(cmd, space - cmd); else cmdname = a_strdup(cmd);