fix out-of-bounds read of the Xinerama screen array with no screens

This can happen if dmenu is run with Xinerama enabled and no screens are
detected.

Also fallback to the first screen if there is no intersection of the root
pointer to the screens found.

Reported by: jb19357 <jb19357@protonmail.com>
Who used Claude to write a report.

I cannot reproduce this issue, but it seems logical.
This commit is contained in:
Hiltjo Posthuma 2026-09-13 20:39:14 +02:00
parent 5453bb65d9
commit 0785a28f1d

View File

@ -639,6 +639,8 @@ setup(void)
#ifdef XINERAMA #ifdef XINERAMA
i = 0; i = 0;
if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) { if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) {
if (n < 1)
die("Xinerama reported no screens");
XGetInputFocus(dpy, &w, &di); XGetInputFocus(dpy, &w, &di);
if (mon >= 0 && mon < n) if (mon >= 0 && mon < n)
i = mon; i = mon;
@ -661,6 +663,9 @@ setup(void)
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
if (INTERSECT(x, y, 1, 1, info[i]) != 0) if (INTERSECT(x, y, 1, 1, info[i]) != 0)
break; break;
/* fallback to the first screen if there is no intersection */
if (i >= n)
i = 0;
x = info[i].x_org; x = info[i].x_org;
y = info[i].y_org + (topbar ? 0 : info[i].height - mh); y = info[i].y_org + (topbar ? 0 : info[i].height - mh);