From b9971a5accf80cd94f803f9e82f0c2fb35000ad9 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 23 May 2021 23:13:26 -0700 Subject: [PATCH] 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. --- root.c | 7 ++++++- tests/test-wallpaper.lua | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/root.c b/root.c index ae683756f..4b5ebfbed 100644 --- a/root.c +++ b/root.c @@ -481,6 +481,11 @@ luaA_root_wallpaper(lua_State *L) { 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); lua_pushboolean(L, root_set_wallpaper(pattern)); /* 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 }, { "fake_input", luaA_root_fake_input }, { "drawins", luaA_root_drawins }, - { "wallpaper", luaA_root_wallpaper }, + { "_wallpaper", luaA_root_wallpaper }, { "size", luaA_root_size }, { "size_mm", luaA_root_size_mm }, { "tags", luaA_root_tags }, diff --git a/tests/test-wallpaper.lua b/tests/test-wallpaper.lua index c337d9dbb..71c82cd0a 100644 --- a/tests/test-wallpaper.lua +++ b/tests/test-wallpaper.lua @@ -133,6 +133,15 @@ end return true 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)