root: Do not end up in an infinite loop if the wallpaper is `nil`.

If `root.wallpaper` was called with `nil` during initialization,
AwesomeWM would get into an infinite restart loop.
This commit is contained in:
Emmanuel Lepage Vallee 2021-05-23 23:13:26 -07:00
parent b0a2d82d8f
commit b9971a5acc
2 changed files with 15 additions and 1 deletions

7
root.c
View File

@ -481,6 +481,11 @@ luaA_root_wallpaper(lua_State *L)
{ {
if(lua_gettop(L) == 1) if(lua_gettop(L) == 1)
{ {
/* Avoid `error()s` down the line. If this happens during
* initialization, AwesomeWM can be stuck in an infinite loop */
if(lua_isnil(L, -1))
return 0;
cairo_pattern_t *pattern = (cairo_pattern_t *)lua_touserdata(L, -1); cairo_pattern_t *pattern = (cairo_pattern_t *)lua_touserdata(L, -1);
lua_pushboolean(L, root_set_wallpaper(pattern)); lua_pushboolean(L, root_set_wallpaper(pattern));
/* Don't return the wallpaper, it's too easy to get memleaks */ /* Don't return the wallpaper, it's too easy to get memleaks */
@ -602,7 +607,7 @@ const struct luaL_Reg awesome_root_methods[] =
{ "cursor", luaA_root_cursor }, { "cursor", luaA_root_cursor },
{ "fake_input", luaA_root_fake_input }, { "fake_input", luaA_root_fake_input },
{ "drawins", luaA_root_drawins }, { "drawins", luaA_root_drawins },
{ "wallpaper", luaA_root_wallpaper }, { "_wallpaper", luaA_root_wallpaper },
{ "size", luaA_root_size }, { "size", luaA_root_size },
{ "size_mm", luaA_root_size_mm }, { "size_mm", luaA_root_size_mm },
{ "tags", luaA_root_tags }, { "tags", luaA_root_tags },

View File

@ -133,6 +133,15 @@ end
return true return true
end) end)
-- Make sure passing `nil` doesn't crash Awesome.
table.insert(steps, function()
root._wallpaper(nil)
root.wallpaper(nil)
return true
end)
runner.run_steps(steps) runner.run_steps(steps)