display: Make sure ping serials are never reused

Using a timestamp twice in a row (e.g. when activating two windows in
response to the same event or due to other bugs) will break the window
detection and show a close dialog on the wrong window. This is a grave
error that should never happen, so check every timestamp before sending
the ping for uniqueness and if the timestamp was already used and its
ping is still pending, log a warning message and don't send the ping.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/891
This commit is contained in:
Jonas Dreßler 2019-12-07 15:24:31 +01:00 committed by Jonas Ådahl
parent 0bf9727a31
commit 9b58033375

View File

@ -2063,6 +2063,7 @@ void
meta_display_ping_window (MetaWindow *window, meta_display_ping_window (MetaWindow *window,
guint32 serial) guint32 serial)
{ {
GSList *l;
MetaDisplay *display = window->display; MetaDisplay *display = window->display;
MetaPingData *ping_data; MetaPingData *ping_data;
@ -2076,6 +2077,19 @@ meta_display_ping_window (MetaWindow *window,
if (!meta_window_can_ping (window)) if (!meta_window_can_ping (window))
return; return;
for (l = display->pending_pings; l; l = l->next)
{
MetaPingData *ping_data = l->data;
if (serial == ping_data->serial)
{
meta_warning ("Ping serial %u was reused for window %s, "
"previous use was for window %s.\n",
serial, window->desc, ping_data->window->desc);
return;
}
}
ping_data = g_new (MetaPingData, 1); ping_data = g_new (MetaPingData, 1);
ping_data->window = window; ping_data->window = window;
ping_data->serial = serial; ping_data->serial = serial;