Fix a invalid pointer crash bug

This changes wibox_t::mouse_over to a proper reference. That way one can't
remove that widget from underneath us which would lead to an unprotected lua error.

Signed-off-by: Uli Schlachter <psychon@znc.in>
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Uli Schlachter 2009-11-21 10:54:44 +01:00 committed by Julien Danjou
parent 7ea3c35cc2
commit 3d60aa7d83
3 changed files with 28 additions and 5 deletions

12
event.c
View File

@ -359,11 +359,19 @@ event_handle_widget_motionnotify(void *object,
luaA_object_push(globalconf.L, *mouse_over);
luaA_object_emit_signal(globalconf.L, -1, "mouse::leave", 0);
lua_pop(globalconf.L, 1);
luaA_object_unref(globalconf.L, *mouse_over);
*mouse_over = NULL;
}
if(widget)
{
/* emit mouse::enter signal on new widget and register it */
/* Get a ref on this widget so that it can't be unref'd from
* underneath us (-> invalid pointer dereference). */
luaA_object_push(globalconf.L, widget);
luaA_object_ref(globalconf.L, -1);
*mouse_over = widget;
/* emit mouse::enter signal on new widget */
luaA_object_push(globalconf.L, widget);
luaA_object_emit_signal(globalconf.L, -1, "mouse::enter", 0);
lua_pop(globalconf.L, 1);
@ -435,7 +443,7 @@ event_handle_leavenotify(void *data __attribute__ ((unused)),
/* emit mouse::leave signal on widget the mouse was over */
luaA_object_emit_signal(globalconf.L, -1, "mouse::leave", 0);
lua_pop(globalconf.L, 1);
wibox->mouse_over = NULL;
wibox_clear_mouse_over(wibox);
}
luaA_object_push(globalconf.L, wibox);

19
wibox.c
View File

@ -59,7 +59,7 @@ static void
wibox_need_update(wibox_t *wibox)
{
wibox->need_update = true;
wibox->mouse_over = NULL;
wibox_clear_mouse_over(wibox);
}
static int
@ -619,6 +619,19 @@ wibox_refresh(void)
}
}
/** Clear the wibox' mouse_over pointer.
* \param wibox The wibox.
*/
void
wibox_clear_mouse_over(wibox_t *wibox)
{
if (wibox->mouse_over)
{
luaA_object_unref(globalconf.L, wibox->mouse_over);
wibox->mouse_over = NULL;
}
}
/** Set a wibox visible or not.
* \param L The Lua VM state.
* \param udx The wibox.
@ -631,7 +644,7 @@ wibox_set_visible(lua_State *L, int udx, bool v)
if(v != wibox->visible)
{
wibox->visible = v;
wibox->mouse_over = NULL;
wibox_clear_mouse_over(wibox);
if(wibox->screen)
{
@ -704,7 +717,7 @@ wibox_detach(lua_State *L, int udx)
/* restore visibility */
wibox->visible = v;
wibox->mouse_over = NULL;
wibox_clear_mouse_over(wibox);
wibox_wipe(wibox);

View File

@ -117,5 +117,7 @@ void wibox_class_setup(lua_State *);
lua_class_t wibox_class;
void wibox_clear_mouse_over(wibox_t *);
#endif
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80