From 0785a28f1d6e27e18ab998d20b0390e2c3ec226c Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sun, 13 Sep 2026 20:39:14 +0200 Subject: [PATCH] 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 Who used Claude to write a report. I cannot reproduce this issue, but it seems logical. --- dmenu.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dmenu.c b/dmenu.c index 64ff973..11a0551 100644 --- a/dmenu.c +++ b/dmenu.c @@ -639,6 +639,8 @@ setup(void) #ifdef XINERAMA i = 0; if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) { + if (n < 1) + die("Xinerama reported no screens"); XGetInputFocus(dpy, &w, &di); if (mon >= 0 && mon < n) i = mon; @@ -661,6 +663,9 @@ setup(void) for (i = 0; i < n; i++) if (INTERSECT(x, y, 1, 1, info[i]) != 0) break; + /* fallback to the first screen if there is no intersection */ + if (i >= n) + i = 0; x = info[i].x_org; y = info[i].y_org + (topbar ? 0 : info[i].height - mh);