From f9f22437e795c3757067f07678dd8791c7574780 Mon Sep 17 00:00:00 2001 From: NRK Date: Fri, 7 Jun 2024 15:19:11 +0000 Subject: [PATCH 1/4] clipmenud: no need to use volatile sig_atomic_t since there's no signal handlers involved and signals are handled with regular code via signalfd. --- src/clipmenud.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clipmenud.c b/src/clipmenud.c index 9374508..bfba67b 100644 --- a/src/clipmenud.c +++ b/src/clipmenud.c @@ -25,7 +25,7 @@ static struct clip_store cs; static struct config cfg; static Window win; -static volatile sig_atomic_t enabled = 1; +static int enabled = 1; static int sig_fd; static struct cm_selections sels[CM_SEL_MAX]; From 5d54cc70fc6d29bde6fac36c036f68f2c69eb1f5 Mon Sep 17 00:00:00 2001 From: NRK Date: Fri, 7 Jun 2024 15:32:40 +0000 Subject: [PATCH 2/4] clipmenud: don't silently ignore arguments otherwise running something like `clipmenud --verbose` gives the false impression of it "working". --- src/clipmenud.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/clipmenud.c b/src/clipmenud.c index bfba67b..33bcf4b 100644 --- a/src/clipmenud.c +++ b/src/clipmenud.c @@ -380,7 +380,9 @@ static int _noreturn_ run(int evt_base) { } #ifndef UNIT_TEST -int main(void) { +int main(int argc, char *argv[]) { + (void)argv; + die_on(argc != 1, "clipmenud doesn't accept any arguments\n"); int evt_base; cfg = setup("clipmenud"); From a31fade900bc0217c1857df20f4ace11f698aaeb Mon Sep 17 00:00:00 2001 From: NRK Date: Fri, 7 Jun 2024 16:10:02 +0000 Subject: [PATCH 3/4] config: range check parsed integers negative values don't make sense for these config vars, so reject them. also reject values that are too large and would get truncated. --- src/config.c | 11 ++++++----- src/config.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/config.c b/src/config.c index bfffaad..bcbcefa 100644 --- a/src/config.c +++ b/src/config.c @@ -74,10 +74,10 @@ int convert_bool(const char *str, void *output) { return -EINVAL; } -int convert_int(const char *str, void *output) { +int convert_positive_int(const char *str, void *output) { char *end; long val = strtol(str, &end, 10); - if (*end != '\0' || end == str) { + if (*end != '\0' || end == str || val < 0 || val > INT_MAX) { return -EINVAL; } *(int *)output = (int)val; @@ -264,10 +264,11 @@ static int config_apply_default_values(struct config_entry entries[], */ int config_setup_internal(FILE *file, struct config *cfg) { struct config_entry entries[] = { - {"max_clips", "CM_MAX_CLIPS", &cfg->max_clips, convert_int, "1000", 0}, + {"max_clips", "CM_MAX_CLIPS", &cfg->max_clips, convert_positive_int, + "1000", 0}, {"max_clips_batch", "CM_MAX_CLIPS_BATCH", &cfg->max_clips_batch, - convert_int, "100", 0}, - {"oneshot", "CM_ONESHOT", &cfg->oneshot, convert_int, "0", 0}, + convert_positive_int, "100", 0}, + {"oneshot", "CM_ONESHOT", &cfg->oneshot, convert_positive_int, "0", 0}, {"own_clipboard", "CM_OWN_CLIPBOARD", &cfg->own_clipboard, convert_bool, "0", 0}, {"selections", "CM_SELECTIONS", &cfg->selections, convert_selections, diff --git a/src/config.h b/src/config.h index 34bce13..e464ab2 100644 --- a/src/config.h +++ b/src/config.h @@ -89,7 +89,7 @@ enum selection_type _nonnull_ storage_atom_to_selection_type(Atom atom, struct cm_selections *sels); int convert_bool(const char *str, void *output); -int convert_int(const char *str, void *output); +int convert_positive_int(const char *str, void *output); int convert_ignore_window(const char *str, void *output); int config_setup_internal(FILE *file, struct config *cfg); void config_free(struct config *cfg); From bd971204452407a3fca51e7ac6fe0aff86fb6c9d Mon Sep 17 00:00:00 2001 From: NRK Date: Fri, 7 Jun 2024 17:39:04 +0000 Subject: [PATCH 4/4] clipmenud: correct cast to size_t --- src/clipmenud.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/clipmenud.c b/src/clipmenud.c index 33bcf4b..3a1f718 100644 --- a/src/clipmenud.c +++ b/src/clipmenud.c @@ -191,8 +191,7 @@ static void maybe_trim(void) { uint64_t cur_clips; expect(cs_len(&cs, &cur_clips) == 0); if ((int)cur_clips > cfg.max_clips_batch) { - expect(cs_trim(&cs, CS_ITER_NEWEST_FIRST, (uint64_t)cfg.max_clips) == - 0); + expect(cs_trim(&cs, CS_ITER_NEWEST_FIRST, (size_t)cfg.max_clips) == 0); } }