summaryrefslogtreecommitdiffstats
path: root/dwm.c
diff options
context:
space:
mode:
authorNRK <nrk@disroot.org>2026-02-17 07:31:35 +0000
committerHiltjo Posthuma <hiltjo@codemadness.org>2026-02-20 15:31:29 +0100
commitc3dd6a829b3f5cb9474bcca787a9c8a86932d75d (patch)
tree256f63f00902a3dd90fca58cadc93e825da69cca /dwm.c
parentgetstate: fix access type and remove redundant cast (diff)
downloaddwm-c3dd6a829b3f5cb9474bcca787a9c8a86932d75d.tar.gz
dwm-c3dd6a829b3f5cb9474bcca787a9c8a86932d75d.zip
more overflow fix in getatomprop()
commit 244fa852 (and a9aa0d8) tried to fix overflow by checking the number of items returned. however this is not sufficient since the format may be lower than 32 bits. to reproduce the crash, i used the reproducer given in commit 244fa85 but changed the XChangeProperty line to the following to set the property to a 1 element 16 bit item: short si = 1; XChangeProperty(d, w, net_wm_state, XA_ATOM, 16, PropModeReplace, (unsigned char *)&si, 1); this client reliably crashes dwm under ASAN since dwm is trying to read a 32 bit value from a 16 bit one. fix it by checking for format == 32 as well. also change the access type from Atom to long, on my machine Atom is typedef-ed to long already but that may not be true everywere. the XGetWindowProperty manpage says format == 32 is returned as `long` so use `long` directly. (N.B: it also might be worth checking if the returned type is XA_ATOM as well, but i wasn't able to cause any crashes by setting different types so i'm leaving it out for now.)
Diffstat (limited to 'dwm.c')
-rw-r--r--dwm.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/dwm.c b/dwm.c
index a5e1ce9..0a67103 100644
--- a/dwm.c
+++ b/dwm.c
@@ -863,15 +863,15 @@ focusstack(const Arg *arg)
863Atom 863Atom
864getatomprop(Client *c, Atom prop) 864getatomprop(Client *c, Atom prop)
865{ 865{
866 int di; 866 int format;
867 unsigned long nitems, dl; 867 unsigned long nitems, dl;
868 unsigned char *p = NULL; 868 unsigned char *p = NULL;
869 Atom da, atom = None; 869 Atom da, atom = None;
870 870
871 if (XGetWindowProperty(dpy, c->win, prop, 0L, sizeof atom, False, XA_ATOM, 871 if (XGetWindowProperty(dpy, c->win, prop, 0L, sizeof atom, False, XA_ATOM,
872 &da, &di, &nitems, &dl, &p) == Success && p) { 872 &da, &format, &nitems, &dl, &p) == Success && p) {
873 if (nitems > 0) 873 if (nitems > 0 && format == 32)
874 atom = *(Atom *)p; 874 atom = *(long *)p;
875 XFree(p); 875 XFree(p);
876 } 876 }
877 return atom; 877 return atom;