diff options
| author | Hiltjo Posthuma <hiltjo@codemadness.org> | 2026-10-13 14:28:33 +0200 |
|---|---|---|
| committer | Hiltjo Posthuma <hiltjo@codemadness.org> | 2026-10-16 13:23:34 +0200 |
| commit | 7283c8c0ac9db8b38bb280576668256023d82fb4 (patch) | |
| tree | d5f925d5020fda87db91c7c3b9e7a4f74377b3c8 | |
| parent | buttonpress: fix status text click area mismatch (diff) | |
| download | dwm-7283c8c0ac9db8b38bb280576668256023d82fb4.tar.gz dwm-7283c8c0ac9db8b38bb280576668256023d82fb4.zip | |
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;
}
| -rw-r--r-- | dwm.c | 26 |
1 files changed, 13 insertions, 13 deletions
| @@ -1968,32 +1968,32 @@ updatesizehints(Client *c) | |||
| 1968 | /* size is uninitialized, ensure that size.flags aren't used */ | 1968 | /* size is uninitialized, ensure that size.flags aren't used */ |
| 1969 | size.flags = PSize; | 1969 | size.flags = PSize; |
| 1970 | if (size.flags & PBaseSize) { | 1970 | if (size.flags & PBaseSize) { |
| 1971 | c->basew = size.base_width; | 1971 | c->basew = MAX(0, size.base_width); |
| 1972 | c->baseh = size.base_height; | 1972 | c->baseh = MAX(0, size.base_height); |
| 1973 | } else if (size.flags & PMinSize) { | 1973 | } else if (size.flags & PMinSize) { |
| 1974 | c->basew = size.min_width; | 1974 | c->basew = MAX(0, size.min_width); |
| 1975 | c->baseh = size.min_height; | 1975 | c->baseh = MAX(0, size.min_height); |
| 1976 | } else | 1976 | } else |
| 1977 | c->basew = c->baseh = 0; | 1977 | c->basew = c->baseh = 0; |
| 1978 | if (size.flags & PResizeInc) { | 1978 | if (size.flags & PResizeInc) { |
| 1979 | c->incw = size.width_inc; | 1979 | c->incw = MAX(0, size.width_inc); |
| 1980 | c->inch = size.height_inc; | 1980 | c->inch = MAX(0, size.height_inc); |
| 1981 | } else | 1981 | } else |
| 1982 | c->incw = c->inch = 0; | 1982 | c->incw = c->inch = 0; |
| 1983 | if (size.flags & PMaxSize) { | 1983 | if (size.flags & PMaxSize) { |
| 1984 | c->maxw = size.max_width; | 1984 | c->maxw = MAX(0, size.max_width); |
| 1985 | c->maxh = size.max_height; | 1985 | c->maxh = MAX(0, size.max_height); |
| 1986 | } else | 1986 | } else |
| 1987 | c->maxw = c->maxh = 0; | 1987 | c->maxw = c->maxh = 0; |
| 1988 | if (size.flags & PMinSize) { | 1988 | if (size.flags & PMinSize) { |
| 1989 | c->minw = size.min_width; | 1989 | c->minw = MAX(0, size.min_width); |
| 1990 | c->minh = size.min_height; | 1990 | c->minh = MAX(0, size.min_height); |
| 1991 | } else if (size.flags & PBaseSize) { | 1991 | } else if (size.flags & PBaseSize) { |
| 1992 | c->minw = size.base_width; | 1992 | c->minw = MAX(0, size.base_width); |
| 1993 | c->minh = size.base_height; | 1993 | c->minh = MAX(0, size.base_height); |
| 1994 | } else | 1994 | } else |
| 1995 | c->minw = c->minh = 0; | 1995 | c->minw = c->minh = 0; |
| 1996 | if (size.flags & PAspect) { | 1996 | if ((size.flags & PAspect) && size.min_aspect.x > 0 && size.max_aspect.y > 0) { |
| 1997 | c->mina = (float)size.min_aspect.y / size.min_aspect.x; | 1997 | c->mina = (float)size.min_aspect.y / size.min_aspect.x; |
| 1998 | c->maxa = (float)size.max_aspect.x / size.max_aspect.y; | 1998 | c->maxa = (float)size.max_aspect.x / size.max_aspect.y; |
| 1999 | } else | 1999 | } else |
