From 7d797387d7fbe17aae5dd9ebf0cc4b5d7812bb7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 20 Mar 2015 12:39:33 +0100 Subject: [PATCH] Add safety check for QueryTree xcb_qeuery_tree should fail and we should not just assume that the call succeeds. Crash reported by Harald Sitter. --- layers.cpp | 30 ++++++++++++++++-------------- xcbutils.h | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/layers.cpp b/layers.cpp index 2eea79beae..ae08207504 100644 --- a/layers.cpp +++ b/layers.cpp @@ -668,23 +668,25 @@ ToplevelList Workspace::xStackingOrder() const foreach (Toplevel * c, stacking_order) x_stacking.append(c); - xcb_window_t *windows = tree.children(); - const auto count = tree->children_len; - int foundUnmanagedCount = unmanaged.count(); - for (unsigned int i = 0; - i < count; - ++i) { - for (auto it = unmanaged.constBegin(); it != unmanaged.constEnd(); ++it) { - Unmanaged *u = *it; - if (u->window() == windows[i]) { - x_stacking.append(u); - foundUnmanagedCount--; + if (!tree.isNull()) { + xcb_window_t *windows = tree.children(); + const auto count = tree->children_len; + int foundUnmanagedCount = unmanaged.count(); + for (unsigned int i = 0; + i < count; + ++i) { + for (auto it = unmanaged.constBegin(); it != unmanaged.constEnd(); ++it) { + Unmanaged *u = *it; + if (u->window() == windows[i]) { + x_stacking.append(u); + foundUnmanagedCount--; + break; + } + } + if (foundUnmanagedCount == 0) { break; } } - if (foundUnmanagedCount == 0) { - break; - } } if (m_compositor) { const_cast< Workspace* >(this)->m_compositor->checkUnredirect(); diff --git a/xcbutils.h b/xcbutils.h index 51c8f4a1ce..3d3880c996 100644 --- a/xcbutils.h +++ b/xcbutils.h @@ -574,7 +574,7 @@ public: explicit Tree(WindowId window) : Wrapper(window) {} inline WindowId *children() { - if (data()->children_len == 0) { + if (isNull() || data()->children_len == 0) { return nullptr; } return xcb_query_tree_children(data());