From 7283c8c0ac9db8b38bb280576668256023d82fb4 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Tue, 13 Oct 2026 14:28:33 +0200 Subject: check and restrict size hint values Could not reproduce a crash, but may mess up window geometry, etc. Test program below to give an idea: cc repro.c -o repro -lX11; ./repro int main(void) { Display *d; int screen; Window root; Window win; d = XOpenDisplay(NULL); if (!d) { fprintf(stderr, "XOpenDisplay failed\n"); return 1; } screen = DefaultScreen(d); root = RootWindow(d, screen); win = XCreateSimpleWindow(d, root, 0, 0, 100, 100, 0, 0, 0); if (!win) { fprintf(stderr, "XCreateSimpleWindow failed\n"); XCloseDisplay(d); return 1; } //XMapWindow(d, win); XMapRaised(d, win); XSizeHints h = {0}; h.flags = PResizeInc | PBaseSize | PMinSize; h.width_inc = -1; h.height_inc = -1; h.base_width = INT_MIN + 500; /* window is 500px wide */ h.base_height = 0; h.min_width = ~0L; h.min_height = ~0L; XSetWMNormalHints(d, win, &h); sleep(3); //XDestroyWindow(d, win); XCloseDisplay(d); return 0; } --- dwm.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'dwm.c') diff --git a/dwm.c b/dwm.c index ab3a84c..5ff6fd4 100644 --- a/dwm.c +++ b/dwm.c @@ -1968,32 +1968,32 @@ updatesizehints(Client *c) /* size is uninitialized, ensure that size.flags aren't used */ size.flags = PSize; if (size.flags & PBaseSize) { - c->basew = size.base_width; - c->baseh = size.base_height; + c->basew = MAX(0, size.base_width); + c->baseh = MAX(0, size.base_height); } else if (size.flags & PMinSize) { - c->basew = size.min_width; - c->baseh = size.min_height; + c->basew = MAX(0, size.min_width); + c->baseh = MAX(0, size.min_height); } else c->basew = c->baseh = 0; if (size.flags & PResizeInc) { - c->incw = size.width_inc; - c->inch = size.height_inc; + c->incw = MAX(0, size.width_inc); + c->inch = MAX(0, size.height_inc); } else c->incw = c->inch = 0; if (size.flags & PMaxSize) { - c->maxw = size.max_width; - c->maxh = size.max_height; + c->maxw = MAX(0, size.max_width); + c->maxh = MAX(0, size.max_height); } else c->maxw = c->maxh = 0; if (size.flags & PMinSize) { - c->minw = size.min_width; - c->minh = size.min_height; + c->minw = MAX(0, size.min_width); + c->minh = MAX(0, size.min_height); } else if (size.flags & PBaseSize) { - c->minw = size.base_width; - c->minh = size.base_height; + c->minw = MAX(0, size.base_width); + c->minh = MAX(0, size.base_height); } else c->minw = c->minh = 0; - if (size.flags & PAspect) { + if ((size.flags & PAspect) && size.min_aspect.x > 0 && size.max_aspect.y > 0) { c->mina = (float)size.min_aspect.y / size.min_aspect.x; c->maxa = (float)size.max_aspect.x / size.max_aspect.y; } else -- cgit v1.3.1