From 2fd6d209995e2466433db1a2e7f0b94ea35b3888 Mon Sep 17 00:00:00 2001 From: patrick96 Date: Wed, 3 Mar 2021 21:55:43 +0100 Subject: [PATCH] fix(xworkspaces): Segfault for wrong _NET_CURRENT_DESKTOP While it shouldn't happen with compliant WMs, it was possibe to crash polybar with _NET_CURRENT_DESKTOP >= _NET_NUMBER_OF_DESKTOPS and this should not be possible. Includes polybar/xpp#31 Fixes #2398 --- include/modules/xworkspaces.hpp | 1 + lib/xpp | 2 +- src/modules/xworkspaces.cpp | 15 +++++++++++---- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/modules/xworkspaces.hpp b/include/modules/xworkspaces.hpp index f98d6465..17578502 100644 --- a/include/modules/xworkspaces.hpp +++ b/include/modules/xworkspaces.hpp @@ -71,6 +71,7 @@ namespace modules { void rebuild_urgent_hints(); void rebuild_desktops(); void rebuild_desktop_states(); + void update_current_desktop(); void action_focus(const string& data); void action_next(); diff --git a/lib/xpp b/lib/xpp index 4d67025c..7a9960bb 160000 --- a/lib/xpp +++ b/lib/xpp @@ -1 +1 @@ -Subproject commit 4d67025cdbcc7f3c65d1a620c97a8443e0a08129 +Subproject commit 7a9960bbb912f0ed66929c978aaeb1c30acf4bfd diff --git a/src/modules/xworkspaces.cpp b/src/modules/xworkspaces.cpp index 2e78b371..e6c3cee4 100644 --- a/src/modules/xworkspaces.cpp +++ b/src/modules/xworkspaces.cpp @@ -95,8 +95,7 @@ namespace modules { // Get desktop details m_desktop_names = get_desktop_names(); - m_current_desktop = ewmh_util::get_current_desktop(); - m_current_desktop_name = m_desktop_names[m_current_desktop]; + update_current_desktop(); rebuild_desktops(); @@ -105,6 +104,15 @@ namespace modules { rebuild_desktop_states(); } + void xworkspaces_module::update_current_desktop() { + m_current_desktop = ewmh_util::get_current_desktop(); + if (m_current_desktop < m_desktop_names.size()) { + m_current_desktop_name = m_desktop_names[m_current_desktop]; + } else { + throw module_error("The current desktop is outside of the number of desktops reported by the WM"); + } + } + /** * Handler for XCB_PROPERTY_NOTIFY events */ @@ -120,8 +128,7 @@ namespace modules { rebuild_clientlist(); rebuild_desktop_states(); } else if (evt->atom == m_ewmh->_NET_CURRENT_DESKTOP) { - m_current_desktop = ewmh_util::get_current_desktop(); - m_current_desktop_name = m_desktop_names[m_current_desktop]; + update_current_desktop(); rebuild_desktop_states(); } else if (evt->atom == WM_HINTS) { rebuild_urgent_hints();