commit 943baf684e57c2277077c6fd19baf956f81308c2
parent 4186491fcfe2e9fc1d8fd0468ad75b7ec4cdced6
Author: Matthias Schoth <mschoth@gmail.com>
Date: Sat, 11 Jul 2026 11:42:05 +0200
[slock][patch][quickcancel] Port to 1.6 and fix clock vulnerability
- Refresh patch for slock 1.6
- Fix severe security bug:
Replace time(NULL) with clock_gettime(CLOCK_MONOTONIC, ...) so the
lock cannot be bypassed by setting the system clock back
Diffstat:
2 files changed, 71 insertions(+), 0 deletions(-)
diff --git a/tools.suckless.org/slock/patches/quickcancel/index.md b/tools.suckless.org/slock/patches/quickcancel/index.md
@@ -7,6 +7,7 @@ Cancel slock by moving the mouse within a certain time-period after slock starte
Download
--------
+* [slock-quickcancel-1.6.diff](slock-quickcancel-1.6.diff)
* [slock-quickcancel-1.4.diff](slock-quickcancel-1.4.diff)
* [slock-quickcancel-20160619-65b8d52.diff](slock-quickcancel-20160619-65b8d52.diff)
diff --git a/tools.suckless.org/slock/patches/quickcancel/slock-quickcancel-1.6.diff b/tools.suckless.org/slock/patches/quickcancel/slock-quickcancel-1.6.diff
@@ -0,0 +1,70 @@
+From: Matthias Schoth <mschoth@gmail.com>
+Date: Sat, 11 Jul 2026 11:15:49 +0200
+Subject: [PATCH] Apply quickcancel
+
+Cancel slock by moving the mouse within a certain time-period after
+slock started. The time-period can be defined in seconds with the
+setting *timetocancel* in the config.h. This is useful if you forgot to
+disable `xautolock` during an activity that requires no input (e.g.
+reading text, watching video).
+
+Changes from the 1.4 version: use CLOCK_MONOTONIC instead of time(NULL)
+to prevent bypassing the lock by setting the system clock back.
+
+---
+ config.def.h | 3 +++
+ slock.c | 9 +++++++++
+ 2 files changed, 12 insertions(+)
+
+diff --git a/config.def.h b/config.def.h
+index 9855e21..e0bf95a 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -10,3 +10,6 @@ static const char *colorname[NUMCOLS] = {
+
+ /* treat a cleared input like a wrong password (color) */
+ static const int failonclear = 1;
++
++/* time in seconds to cancel lock with mouse movement */
++static const int timetocancel = 4;
+diff --git a/slock.c b/slock.c
+index f16781f..212b482 100644
+--- a/slock.c
++++ b/slock.c
+@@ -13,6 +13,7 @@
+ #include <stdio.h>
+ #include <string.h>
+ #include <unistd.h>
++#include <time.h>
+ #include <spawn.h>
+ #include <sys/types.h>
+ #include <X11/extensions/Xrandr.h>
+@@ -25,6 +26,8 @@
+
+ char *argv0;
+
++static struct timespec locktime;
++
+ enum {
+ INIT,
+ INPUT,
+@@ -142,6 +145,9 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
+ oldc = INIT;
+
+ while (running && !XNextEvent(dpy, &ev)) {
++ struct timespec now;
++ clock_gettime(CLOCK_MONOTONIC, &now);
++ running = !((now.tv_sec - locktime.tv_sec < timetocancel) && (ev.type == MotionNotify));
+ if (ev.type == KeyPress) {
+ explicit_bzero(&buf, sizeof(buf));
+ num = XLookupString(&ev.xkey, buf, sizeof(buf), &ksym, 0);
+@@ -280,6 +286,7 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
+ XRRSelectInput(dpy, lock->win, RRScreenChangeNotifyMask);
+
+ XSelectInput(dpy, lock->root, SubstructureNotifyMask);
++ clock_gettime(CLOCK_MONOTONIC, &locktime);
+ return lock;
+ }
+
+--
+2.23.0