Compare commits

..

14 Commits
6.6 ... master

Author SHA1 Message Date
1bae806fe5 fix: comment out main, so there is only one main signature.
dwm.c also has a main function defined.
2026-01-25 12:46:27 +01:00
2f76a5cc49 fix: forgot to include half of the libraries. 2026-01-25 12:46:04 +01:00
ab2253a0ee Ignore compile_commands.json 2026-01-25 12:39:49 +01:00
c23f9dfe2e Move config.mk into Makefile, and delete config.mk.
config.mk shall now contain user-specific configurations, and thus is
now ignored.
2026-01-25 12:39:49 +01:00
eda3495acf fix: change = to := 2026-01-25 12:37:29 +01:00
1448916be3 Rework makefile and worktree.
Moved most source files to /src/
Renamed `LICENSE` to `COPYING` to reduce (my personal) misspellings.
Rewrote Makefile to be more Quinn-friendly, and removed some components
not necessary for me, since this is a personal project.
2026-01-25 12:20:47 +01:00
f12825443e Specify /bin specifically, as opposed to any directory called bin/ 2026-01-25 09:23:53 +01:00
c750f87edd Add .gitignore 2026-01-19 19:12:47 +01:00
Chris Down
a9aa0d8ffb dwm: Fix getatomprop regression from heap overflow fix
Commit 244fa852fe ("dwm: Fix heap buffer overflow in getatomprop")
introduced a check for dl > 0 before dereferencing the property pointer.
However, I missed that the variable dl is passed to XGetWindowProperty
for both nitems_return and bytes_after_return parameters:

    XGetWindowProperty(..., &dl, &dl, &p)

The final value in dl is bytes_after_return, not nitems_return. For a
successfully read property, bytes_after is typically 0 (indicating all
data was retrieved), so the check `dl > 0` is always false and dwm never
reads any atom properties. So this is safe, but not very helpful :-)

dl is probably just a dummy variable anyway, so fix by using a separate
variable for nitems, and check nitems > 0 as originally intended.
2026-01-16 14:13:51 +01:00
Hiltjo Posthuma
85fe518c1a bump version to 6.7
Put the maintainer at the top and bump years (time flies).
2026-01-10 11:31:44 +01:00
Chris Down
244fa852fe dwm: Fix heap buffer overflow in getatomprop
When getatomprop() is called, it invokes XGetWindowProperty() to
retrieve an Atom. If the property exists but has zero elements (length
0), Xlib returns Success and sets p to a valid, non-NULL memory address
containing a single null byte.

However, dl (that is, the number of items) is 0. dwm blindly casts p to
Atom* and dereferences it. While Xlib guarantees that p is safe to read
as a string (that is, it is null-terminated), it does _not_ guarantee it
is safe to read as an Atom (an unsigned long).

The Atom type is a typedef for unsigned long. Reading an Atom (which
thus will either likely be 4 or 8 bytes) from a 1-byte allocated buffer
results in a heap buffer overflow. Since property content is user
controlled, this allows any client to trigger an out of bounds read
simply by setting a property with format 32 and length 0.

An example client which reliably crashes dwm under ASAN:

    #include <X11/Xlib.h>
    #include <X11/Xatom.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>

    int main(void) {
        Display *d;
        Window root, w;
        Atom net_wm_state;

        d = XOpenDisplay(NULL);
        if (!d) return 1;

        root = DefaultRootWindow(d);
        w = XCreateSimpleWindow(d, root, 10, 10, 200, 200, 1, 0, 0);
        net_wm_state = XInternAtom(d, "_NET_WM_STATE", False);
        if (net_wm_state == None) return 1;

        XChangeProperty(d, w, net_wm_state, XA_ATOM, 32,
                        PropModeReplace, NULL, 0);
        XMapWindow(d, w);
        XSync(d, False);
        sleep(1);

        XCloseDisplay(d);
        return 0;
    }

In order to avoid this, check that the number of items returned is
greater than zero before dereferencing the pointer.
2026-01-10 11:27:23 +01:00
Hiltjo Posthuma
7c3abae4e6 drw.c: drw_scm_free: call free inside
Because drw_scm_create() allocates it.
2025-09-29 18:48:27 +02:00
Hiltjo Posthuma
93f26863d1 cleanup schemes and colors 2025-09-27 12:10:17 +02:00
Hiltjo Posthuma
74edc27caa config: make refreshrate for mouse move/resize a config option
Bump the default from 60 to 120.
2025-08-12 19:17:20 +02:00
12 changed files with 136 additions and 79 deletions

20
.gitignore vendored Normal file
View File

@@ -0,0 +1,20 @@
# Ignore dotfiles by default
.*
# Ignore common (generated) file types
*.a
*.o
*.d
*.so
*.out
*.hex
*.gz
# Ignore specific project files
compile_commands.json
/bin/
/config.mk
# Unignore specific files.
!.gitignore
!.clang-format

View File

@@ -1,5 +1,6 @@
MIT/X Consortium License
© 2010-2026 Hiltjo Posthuma <hiltjo@codemadness.org>
© 2006-2019 Anselm R Garbe <anselm@garbe.ca>
© 2006-2009 Jukka Salmi <jukka at salmi dot ch>
© 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com>
@@ -11,7 +12,6 @@ MIT/X Consortium License
© 2008 Martin Hurton <martin dot hurton at gmail dot com>
© 2008 Neale Pickett <neale dot woozle dot org>
© 2009 Mate Nagy <mnagy at port70 dot net>
© 2010-2016 Hiltjo Posthuma <hiltjo@codemadness.org>
© 2010-2012 Connor Lane Smith <cls@lubutu.com>
© 2011 Christoph Lohmann <20h@r-36.net>
© 2015-2016 Quentin Rameau <quinq@fifth.space>

107
Makefile
View File

@@ -1,45 +1,92 @@
# dwm - dynamic window manager
# See LICENSE file for copyright and license details.
include config.mk
-include config.mk
SRC = drw.c dwm.c util.c
OBJ = ${SRC:.c=.o}
VERSION = 6.7
all: dwm
INSTALL ?= install
GZIP ?= gzip
TAR ?= tar
.c.o:
${CC} -c ${CFLAGS} $<
CFLAGS := -Os $(CFLAGS) -g -std=gnu99\
-Wall -Wextra -Wpedantic -Wno-pointer-arith
CPPFLAGS := -DNDEBUG $(CPPFLAGS)\
-DVERSION=\"$(VERSION)\" -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=700L -DXINERAMA
LDFLAGS := -flto $(LDFLAGS)
LDLIBS := $(LDLIBS) -lm
${OBJ}: config.h config.mk
# Use pkg-config to locate dependencies, and set the correct flags.
ifeq (,$(shell command -v pkg-config))
$(error Failed to locate pkg-config, please make sure it is installed or acessible through PATH.)
else
CPPFLAGS += $(shell pkg-config --cflags-only-I fontconfig freetype2 x11 xft xinerama)
LDFLAGS += $(shell pkg-config --libs-only-L fontconfig freetype2 x11 xft xinerama)
LDLIBS += $(shell pkg-config --libs-only-l fontconfig freetype2 x11 xft xinerama)
endif
config.h:
cp config.def.h $@
SRC := $(wildcard src/*.c)
OBJ := $(addsuffix .o,$(SRC))
DEP := $(addsuffix .d,$(SRC))
dwm: ${OBJ}
${CC} -o $@ ${OBJ} ${LDFLAGS}
# Set Q to @ to silence commands being printed, unless --no-silent has been set
ifeq (0, $(words $(findstring --no-silent,$(MAKEFLAGS))))
Q=@
endif
clean:
rm -f dwm ${OBJ} dwm-${VERSION}.tar.gz
msg = @printf '%-8s %s\n' "$(1)" "$(2)"
dist: clean
mkdir -p dwm-${VERSION}
cp -R LICENSE Makefile README config.def.h config.mk\
dwm.1 drw.h util.h ${SRC} dwm.png transient.c dwm-${VERSION}
tar -cf dwm-${VERSION}.tar dwm-${VERSION}
gzip dwm-${VERSION}.tar
rm -rf dwm-${VERSION}
.PHONY:
all: bin/dwm
install: all
mkdir -p ${DESTDIR}${PREFIX}/bin
cp -f dwm ${DESTDIR}${PREFIX}/bin
chmod 755 ${DESTDIR}${PREFIX}/bin/dwm
mkdir -p ${DESTDIR}${MANPREFIX}/man1
sed "s/VERSION/${VERSION}/g" < dwm.1 > ${DESTDIR}${MANPREFIX}/man1/dwm.1
chmod 644 ${DESTDIR}${MANPREFIX}/man1/dwm.1
.PHONY:
install: $(DESTDIR)/bin/dwm $(DESTDIR)/share/man/man1/dwm.1.gz
$(DESTDIR)/bin/%: bin/%
$(call msg,INSTALL,$@)
$(Q)$(INSTALL) -D -m0755 $< $@
$(DESTDIR)/share/man/%: man/%
$(call msg,INSTALL,$@)
$(Q)$(INSTALL) -D -m0644 $< $@
.PHONY:
uninstall:
rm -f ${DESTDIR}${PREFIX}/bin/dwm\
${DESTDIR}${MANPREFIX}/man1/dwm.1
$(Q)$(RM) $(DESTDIR)/bin/dwm\
$(DESTDIR)/share/man/man1/dwm.1.gz
.PHONY: all clean dist install uninstall
.PHONY:
clean:
$(call msg,CLEAN,src/)
$(Q)$(RM) $(OBJ)
$(call msg,CLEAN,man/)
$(Q)$(RM) $(MAN)
$(call msg,CLEAN,bin/)
$(Q)$(RM) -r bin/
# Links together the object files into the final binary.
bin/dwm: $(OBJ) | bin/
$(call msg,LD,$@)
$(Q)$(CC) $(LDFLAGS) $(LDLIBS) -o $@ $^
# Compiles C sources into Object files
%.c.o: %.c
$(call msg,CC,$@)
$(Q)$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
# Compress files requested for compression using GZIP
%.gz: %
$(call msg,GZIP,$@)
$(Q)$(GZIP) -k $<
# Create directories
%/:
$(call msg-mkdir,$@)
$(Q)mkdir $@
# Generate and include dependencies,
# ignoring any errors that may occur when doing so.
%.c.d: %.c
$(Q)$(CC) -MM $(CPPFLAGS) -MF $@ $<
ifeq (0, $(words $(findstring $(MAKECMDGOALS), clean)))
-include $(DEP)
endif

View File

@@ -1,39 +0,0 @@
# dwm version
VERSION = 6.6
# Customize below to fit your system
# paths
PREFIX = /usr/local
MANPREFIX = ${PREFIX}/share/man
X11INC = /usr/X11R6/include
X11LIB = /usr/X11R6/lib
# Xinerama, comment if you don't want it
XINERAMALIBS = -lXinerama
XINERAMAFLAGS = -DXINERAMA
# freetype
FREETYPELIBS = -lfontconfig -lXft
FREETYPEINC = /usr/include/freetype2
# OpenBSD (uncomment)
#FREETYPEINC = ${X11INC}/freetype2
#MANPREFIX = ${PREFIX}/man
# includes and libs
INCS = -I${X11INC} -I${FREETYPEINC}
LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS}
# flags
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
#CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS}
CFLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Os ${INCS} ${CPPFLAGS}
LDFLAGS = ${LIBS}
# Solaris
#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
#LDFLAGS = ${LIBS}
# compiler and linker
CC = cc

View File

@@ -36,6 +36,7 @@ static const float mfact = 0.55; /* factor of master area size [0.05..0.95]
static const int nmaster = 1; /* number of clients in master area */
static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */
static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */
static const int refreshrate = 120; /* refresh rate (per second) for client move/resize */
static const Layout layouts[] = {
/* symbol arrange function */

View File

@@ -178,8 +178,7 @@ drw_clr_create(Drw *drw, Clr *dest, const char *clrname)
die("error, cannot allocate color '%s'", clrname);
}
/* Wrapper to create color schemes. The caller has to call free(3) on the
* returned color scheme when done using it. */
/* Create color schemes. */
Clr *
drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
{
@@ -187,7 +186,7 @@ drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
Clr *ret;
/* need at least two colors for a scheme */
if (!drw || !clrnames || clrcount < 2 || !(ret = ecalloc(clrcount, sizeof(XftColor))))
if (!drw || !clrnames || clrcount < 2 || !(ret = ecalloc(clrcount, sizeof(Clr))))
return NULL;
for (i = 0; i < clrcount; i++)
@@ -195,6 +194,30 @@ drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
return ret;
}
void
drw_clr_free(Drw *drw, Clr *c)
{
if (!drw || !c)
return;
/* c is typedef XftColor Clr */
XftColorFree(drw->dpy, DefaultVisual(drw->dpy, drw->screen),
DefaultColormap(drw->dpy, drw->screen), c);
}
void
drw_scm_free(Drw *drw, Clr *scm, size_t clrcount)
{
size_t i;
if (!drw || !scm)
return;
for (i = 0; i < clrcount; i++)
drw_clr_free(drw, &scm[i]);
free(scm);
}
void
drw_setfontset(Drw *drw, Fnt *set)
{

View File

@@ -40,7 +40,9 @@ void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned in
/* Colorscheme abstraction */
void drw_clr_create(Drw *drw, Clr *dest, const char *clrname);
void drw_clr_free(Drw *drw, Clr *c);
Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount);
void drw_scm_free(Drw *drw, Clr *scm, size_t clrcount);
/* Cursor abstraction */
Cur *drw_cur_create(Drw *drw, int shape);

View File

@@ -486,7 +486,7 @@ cleanup(void)
for (i = 0; i < CurLast; i++)
drw_cur_free(drw, cursor[i]);
for (i = 0; i < LENGTH(colors); i++)
free(scheme[i]);
drw_scm_free(drw, scheme[i], 3);
free(scheme);
XDestroyWindow(dpy, wmcheckwin);
drw_free(drw);
@@ -864,12 +864,13 @@ Atom
getatomprop(Client *c, Atom prop)
{
int di;
unsigned long dl;
unsigned long nitems, dl;
unsigned char *p = NULL;
Atom da, atom = None;
if (XGetWindowProperty(dpy, c->win, prop, 0L, sizeof atom, False, XA_ATOM,
&da, &di, &dl, &dl, &p) == Success && p) {
&da, &di, &nitems, &dl, &p) == Success && p) {
if (nitems > 0)
atom = *(Atom *)p;
XFree(p);
}
@@ -1171,7 +1172,7 @@ movemouse(const Arg *arg)
handler[ev.type](&ev);
break;
case MotionNotify:
if ((ev.xmotion.time - lasttime) <= (1000 / 60))
if ((ev.xmotion.time - lasttime) <= (1000 / refreshrate))
continue;
lasttime = ev.xmotion.time;
@@ -1325,7 +1326,7 @@ resizemouse(const Arg *arg)
handler[ev.type](&ev);
break;
case MotionNotify:
if ((ev.xmotion.time - lasttime) <= (1000 / 60))
if ((ev.xmotion.time - lasttime) <= (1000 / refreshrate))
continue;
lasttime = ev.xmotion.time;

View File

@@ -5,6 +5,7 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
/*
int main(void) {
Display *d;
Window r, f, t = None;
@@ -40,3 +41,4 @@ int main(void) {
XCloseDisplay(d);
exit(0);
}
*/

View File

View File