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.
This commit is contained in:
Martin Gräßlin 2015-03-20 12:39:33 +01:00
parent e2c422dcb5
commit 7d797387d7
2 changed files with 17 additions and 15 deletions

View file

@ -668,23 +668,25 @@ ToplevelList Workspace::xStackingOrder() const
foreach (Toplevel * c, stacking_order) foreach (Toplevel * c, stacking_order)
x_stacking.append(c); x_stacking.append(c);
xcb_window_t *windows = tree.children(); if (!tree.isNull()) {
const auto count = tree->children_len; xcb_window_t *windows = tree.children();
int foundUnmanagedCount = unmanaged.count(); const auto count = tree->children_len;
for (unsigned int i = 0; int foundUnmanagedCount = unmanaged.count();
i < count; for (unsigned int i = 0;
++i) { i < count;
for (auto it = unmanaged.constBegin(); it != unmanaged.constEnd(); ++it) { ++i) {
Unmanaged *u = *it; for (auto it = unmanaged.constBegin(); it != unmanaged.constEnd(); ++it) {
if (u->window() == windows[i]) { Unmanaged *u = *it;
x_stacking.append(u); if (u->window() == windows[i]) {
foundUnmanagedCount--; x_stacking.append(u);
foundUnmanagedCount--;
break;
}
}
if (foundUnmanagedCount == 0) {
break; break;
} }
} }
if (foundUnmanagedCount == 0) {
break;
}
} }
if (m_compositor) { if (m_compositor) {
const_cast< Workspace* >(this)->m_compositor->checkUnredirect(); const_cast< Workspace* >(this)->m_compositor->checkUnredirect();

View file

@ -574,7 +574,7 @@ public:
explicit Tree(WindowId window) : Wrapper<TreeData, xcb_window_t>(window) {} explicit Tree(WindowId window) : Wrapper<TreeData, xcb_window_t>(window) {}
inline WindowId *children() { inline WindowId *children() {
if (data()->children_len == 0) { if (isNull() || data()->children_len == 0) {
return nullptr; return nullptr;
} }
return xcb_query_tree_children(data()); return xcb_query_tree_children(data());