From 65cb721c9eb7b5d80267378790dee93e9db0223c Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sat, 5 Sep 2026 12:20:57 +0200 Subject: [PATCH] remove support for running post lock command This command was used for example to suspend-to-ram (man page example). On Linux running this command inherits OOM killer immunity. This could be abused by an other local user on the same machine (abusing resources). To keep the use-case for suspend-to-ram an user could write a wrapper script for it, outside the scope of slock. Simplify argument handling, because the post-lock command parameter is removed. Reported by: Acts1631 --- Makefile | 4 ++-- arg.h | 65 -------------------------------------------------------- slock.1 | 11 +--------- slock.c | 22 ++++--------------- 4 files changed, 7 insertions(+), 95 deletions(-) delete mode 100644 arg.h diff --git a/Makefile b/Makefile index 6d74b21..c41e57e 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ all: slock .c.o: ${CC} -c ${CFLAGS} $< -${OBJ}: config.h config.mk arg.h util.h +${OBJ}: config.h config.mk util.h config.h: cp config.def.h $@ @@ -25,7 +25,7 @@ clean: dist: clean mkdir -p slock-${VERSION} cp -R LICENSE Makefile README slock.1 config.mk \ - ${SRC} config.def.h arg.h util.h slock-${VERSION} + ${SRC} config.def.h util.h slock-${VERSION} tar -cf slock-${VERSION}.tar slock-${VERSION} gzip slock-${VERSION}.tar rm -rf slock-${VERSION} diff --git a/arg.h b/arg.h deleted file mode 100644 index 0b23c53..0000000 --- a/arg.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copy me if you can. - * by 20h - */ - -#ifndef ARG_H__ -#define ARG_H__ - -extern char *argv0; - -/* use main(int argc, char *argv[]) */ -#define ARGBEGIN for (argv0 = *argv, argv++, argc--;\ - argv[0] && argv[0][0] == '-'\ - && argv[0][1];\ - argc--, argv++) {\ - char argc_;\ - char **argv_;\ - int brk_;\ - if (argv[0][1] == '-' && argv[0][2] == '\0') {\ - argv++;\ - argc--;\ - break;\ - }\ - for (brk_ = 0, argv[0]++, argv_ = argv;\ - argv[0][0] && !brk_;\ - argv[0]++) {\ - if (argv_ != argv)\ - break;\ - argc_ = argv[0][0];\ - switch (argc_) - -/* Handles obsolete -NUM syntax */ -#define ARGNUM case '0':\ - case '1':\ - case '2':\ - case '3':\ - case '4':\ - case '5':\ - case '6':\ - case '7':\ - case '8':\ - case '9' - -#define ARGEND }\ - } - -#define ARGC() argc_ - -#define ARGNUMF() (brk_ = 1, estrtonum(argv[0], 0, INT_MAX)) - -#define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\ - ((x), abort(), (char *)0) :\ - (brk_ = 1, (argv[0][1] != '\0')?\ - (&argv[0][1]) :\ - (argc--, argv++, argv[0]))) - -#define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\ - (char *)0 :\ - (brk_ = 1, (argv[0][1] != '\0')?\ - (&argv[0][1]) :\ - (argc--, argv++, argv[0]))) - -#define LNGARG() &argv[0][0] - -#endif diff --git a/slock.1 b/slock.1 index 40c15e1..e485992 100644 --- a/slock.1 +++ b/slock.1 @@ -1,4 +1,4 @@ -.Dd October 6, 2023 +.Dd September 5, 2026 .Dt SLOCK 1 .Os .Sh NAME @@ -7,14 +7,9 @@ .Sh SYNOPSIS .Nm .Op Fl v -.Op Ar cmd Op Ar arg ... .Sh DESCRIPTION .Nm is a simple X screen locker. -If provided, -.Ar cmd -is executed after the screen has been locked. -.Pp The options are as follows: .Bl -tag -width Ds .It Fl v @@ -22,10 +17,6 @@ Print version information to stdout and exit. .El .Sh EXIT STATUS .Ex -std -.Sh EXAMPLES -$ -.Nm -/usr/sbin/s2ram .Sh SECURITY CONSIDERATIONS To make sure a locked screen can not be bypassed by switching VTs or killing the X server with Ctrl+Alt+Backspace, it is recommended diff --git a/slock.c b/slock.c index 3cede0f..9c587e1 100644 --- a/slock.c +++ b/slock.c @@ -13,14 +13,12 @@ #include #include #include -#include #include #include #include #include #include -#include "arg.h" #include "util.h" char *argv0; @@ -304,7 +302,7 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen) static void usage(void) { - die("usage: slock [-v] [cmd [arg ...]]\n"); + die("usage: slock [-v]\n"); } int @@ -319,13 +317,12 @@ main(int argc, char **argv) { Display *dpy; int s, nlocks, nscreens; - ARGBEGIN { - case 'v': + if (argc > 1 && !strcmp(argv[1], "-v")) { puts("slock-"VERSION); return 0; - default: + } else if (argc > 1) { usage(); - } ARGEND + } /* validate drop-user and -group */ errno = 0; @@ -378,17 +375,6 @@ main(int argc, char **argv) { if (nlocks != nscreens) return 1; - /* run post-lock command */ - if (argc > 0) { - pid_t pid; - extern char **environ; - int err = posix_spawnp(&pid, argv[0], NULL, NULL, argv, environ); - if (err) { - die("slock: failed to execute post-lock command: %s: %s\n", - argv[0], strerror(err)); - } - } - /* everything is now blank. Wait for the correct password */ readpw(dpy, &rr, locks, nscreens, hash);