From b8eeb76608f8bdb4fd75f71deb3d45f73b984710 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Tue, 9 Aug 2016 18:29:22 -0400 Subject: [PATCH 1/2] spawn: Fix crash when called with an empty table. The spawn code didn't properly handle the case where there is an empty command stream. In that case, no error is reported as there is simply nothing to do. The error message was probed and this caused an invalid read and crash. Fix #1033 --- spawn.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spawn.c b/spawn.c index 40e9ef8c7..e089b62f4 100644 --- a/spawn.c +++ b/spawn.c @@ -414,8 +414,12 @@ luaA_spawn(lua_State *L) if(!argv || !argv[0]) { g_strfreev(argv); - luaA_warn(L, "spawn: parse error: %s", error->message); - g_error_free(error); + if (error) { + luaA_warn(L, "spawn: parse error: %s", error->message); + g_error_free(error); + } + else + luaA_warn(L, "spawn: There is nothing to execute"); return 1; } From da62aec055c21e68d1c9df46f28581b510c62a0a Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Tue, 9 Aug 2016 18:50:34 -0400 Subject: [PATCH 2/2] tests: Test spawn empty command corner case --- tests/test-spawn.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test-spawn.lua b/tests/test-spawn.lua index 63d87c155..0a79a9c2a 100644 --- a/tests/test-spawn.lua +++ b/tests/test-spawn.lua @@ -6,6 +6,9 @@ local spawn = require("awful.spawn") local spawns_done = 0 local exit_yay, exit_snd = nil, nil +-- * Using spawn with array is already covered by the test client. +-- * spawn with startup notification is covered by test-spawn-snid.lua + local steps = { function(count) if count == 1 then @@ -62,6 +65,17 @@ local steps = { return true end end, + function() + -- Test empty command table + spawn{} + return true + end, + function() + -- Test empty command string + spawn("") + assert(#client.get() == 0) + return true + end, } runner.run_steps(steps)