Re: [hackers] [dwm][patch] dwm crashes when opening 50+ clients (tile layout)

From: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Sat, 25 Apr 2020 13:40:11 +0200

On Thu, Apr 23, 2020 at 09:50:54AM +0200, bakkeby wrote:
> Many users new to dwm find themselves caught out by being kicked out to the login manager (dwm crashing) when they open 50+ clients for demonstration purposes. The number of clients reported varies depending on the resolution of the monitor.
>
> The cause of this is due to how the default tile layout calculates the height of the next client based on the position of the previous client. Because clients have a minimum size the (ty) position can exceed that of the window height, resulting in (m->wh - ty) becoming negative. The negative height stored as an unsigned int results in a very large height ultimately resulting in dwm crashing.
>
> This patch adds safeguards to prevent the ty and my positions from exceeding that of the window height.
> ---
> dwm.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/dwm.c b/dwm.c
> index fb1e326..9fd0286 100644
> --- a/dwm.c
> +++ b/dwm.c
> _AT_@ -1689,11 +1689,13 @@ tile(Monitor *m)
> if (i < m->nmaster) {
> h = (m->wh - my) / (MIN(n, m->nmaster) - i);
> resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0);
> - my += HEIGHT(c);
> + if (my + HEIGHT(c) < m->wh)
> + my += HEIGHT(c);
> } else {
> h = (m->wh - ty) / (n - i);
> resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0);
> - ty += HEIGHT(c);
> + if (ty + HEIGHT(c) < m->wh)
> + ty += HEIGHT(c);
> }
> }
>
> --
> 2.17.1
>
>

Thanks for the patch! It is pushed to master.

On my system it did not crash dwm itself, but it did crash some applications
(custom window program) after some point. This was tested with a script
spamming 100 simple X11 window applications.

-- 
Kind regards,
Hiltjo
Received on Sat Apr 25 2020 - 13:40:11 CEST

This archive was generated by hypermail 2.3.0 : Sat Apr 25 2020 - 13:48:35 CEST