diff --git a/CHANGELOG.md b/CHANGELOG.md index d102c7d..74021a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,10 @@ “refreshed” it (https://codeberg.org/dnkl/yambar/issues/116). * network: failure to retrieve wireless attributes (SSID, RX/TX bitrate, signal strength etc). +* Integer options that were supposed to be >= 0 were incorrectly + allowed, leading to various bad things; including yambar crashing, + or worse, the compositor crashing + (https://codeberg.org/dnkl/yambar/issues/129). ### Security diff --git a/bar/wayland.c b/bar/wayland.c index 90d1103..a5a6731 100644 --- a/bar/wayland.c +++ b/bar/wayland.c @@ -1025,7 +1025,8 @@ setup(struct bar *_bar) ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT | top_or_bottom); - update_size(backend); + if (!update_size(backend)) + return false; assert(backend->monitor == NULL || backend->width / backend->monitor->scale <= backend->monitor->width_px); diff --git a/config-verify.c b/config-verify.c index 63efef3..b92fb71 100644 --- a/config-verify.c +++ b/config-verify.c @@ -50,6 +50,17 @@ conf_verify_int(keychain_t *chain, const struct yml_node *node) return false; } +bool +conf_verify_unsigned(keychain_t *chain, const struct yml_node *node) +{ + if (yml_value_is_int(node) && yml_value_as_int(node) >= 0) + return true; + + LOG_ERR("%s: value is not a positive integer: '%s'", + conf_err_prefix(chain, node), yml_value_as_string(node)); + return false; +} + bool conf_verify_bool(keychain_t *chain, const struct yml_node *node) { @@ -381,17 +392,17 @@ static bool verify_bar_border(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { - {"width", false, &conf_verify_int}, - {"left-width", false, &conf_verify_int}, - {"right-width", false, &conf_verify_int}, - {"top-width", false, &conf_verify_int}, - {"bottom-width", false, &conf_verify_int}, + {"width", false, &conf_verify_unsigned}, + {"left-width", false, &conf_verify_unsigned}, + {"right-width", false, &conf_verify_unsigned}, + {"top-width", false, &conf_verify_unsigned}, + {"bottom-width", false, &conf_verify_unsigned}, {"color", false, &conf_verify_color}, - {"margin", false, &conf_verify_int}, - {"left-margin", false, &conf_verify_int}, - {"right-margin", false, &conf_verify_int}, - {"top-margin", false, &conf_verify_int}, - {"bottom-margin", false, &conf_verify_int}, + {"margin", false, &conf_verify_unsigned}, + {"left-margin", false, &conf_verify_unsigned}, + {"right-margin", false, &conf_verify_unsigned}, + {"top-margin", false, &conf_verify_unsigned}, + {"bottom-margin", false, &conf_verify_unsigned}, {NULL, false, NULL}, }; @@ -422,20 +433,20 @@ conf_verify_bar(const struct yml_node *bar) chain_push(&chain, "bar"); static const struct attr_info attrs[] = { - {"height", true, &conf_verify_int}, + {"height", true, &conf_verify_unsigned}, {"location", true, &verify_bar_location}, {"background", true, &conf_verify_color}, {"monitor", false, &conf_verify_string}, {"layer", false, &verify_bar_layer}, - {"spacing", false, &conf_verify_int}, - {"left-spacing", false, &conf_verify_int}, - {"right-spacing", false, &conf_verify_int}, + {"spacing", false, &conf_verify_unsigned}, + {"left-spacing", false, &conf_verify_unsigned}, + {"right-spacing", false, &conf_verify_unsigned}, - {"margin", false, &conf_verify_int}, - {"left-margin", false, &conf_verify_int}, - {"right-margin", false, &conf_verify_int}, + {"margin", false, &conf_verify_unsigned}, + {"left-margin", false, &conf_verify_unsigned}, + {"right-margin", false, &conf_verify_unsigned}, {"border", false, &verify_bar_border}, {"font", false, &conf_verify_font}, @@ -445,7 +456,7 @@ conf_verify_bar(const struct yml_node *bar) {"center", false, &verify_module_list}, {"right", false, &verify_module_list}, - {"trackpad-sensitivity", false, &conf_verify_int}, + {"trackpad-sensitivity", false, &conf_verify_unsigned}, {NULL, false, NULL}, }; diff --git a/config-verify.h b/config-verify.h index 5afe3f6..8e5ab29 100644 --- a/config-verify.h +++ b/config-verify.h @@ -32,6 +32,7 @@ const char *conf_err_prefix( bool conf_verify_string(keychain_t *chain, const struct yml_node *node); bool conf_verify_int(keychain_t *chain, const struct yml_node *node); +bool conf_verify_unsigned(keychain_t *chain, const struct yml_node *node); bool conf_verify_bool(keychain_t *chain, const struct yml_node *node); bool conf_verify_enum(keychain_t *chain, const struct yml_node *node, diff --git a/decorations/border.c b/decorations/border.c index ac50c33..5868e88 100644 --- a/decorations/border.c +++ b/decorations/border.c @@ -76,7 +76,7 @@ verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { {"color", true, &conf_verify_color}, - {"size", false, &conf_verify_int}, + {"size", false, &conf_verify_unsigned}, DECORATION_COMMON_ATTRS, }; diff --git a/decorations/underline.c b/decorations/underline.c index a700bec..5b8bbd3 100644 --- a/decorations/underline.c +++ b/decorations/underline.c @@ -54,7 +54,7 @@ static bool verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { - {"size", true, &conf_verify_int}, + {"size", true, &conf_verify_unsigned}, {"color", true, &conf_verify_color}, DECORATION_COMMON_ATTRS, }; diff --git a/doc/yambar-modules-script.5.scd b/doc/yambar-modules-script.5.scd index 7ba46d8..c1f31c6 100644 --- a/doc/yambar-modules-script.5.scd +++ b/doc/yambar-modules-script.5.scd @@ -77,6 +77,7 @@ User defined. : Arguments to pass to the script/binary. | poll-interval : integer +: no : Number of seconds between each script run. If unset, continuous mode is used. diff --git a/modules/battery.c b/modules/battery.c index 4f17de4..e6526f5 100644 --- a/modules/battery.c +++ b/modules/battery.c @@ -496,7 +496,7 @@ verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { {"name", true, &conf_verify_string}, - {"poll-interval", false, &conf_verify_int}, + {"poll-interval", false, &conf_verify_unsigned}, MODULE_COMMON_ATTRS, }; diff --git a/modules/i3.c b/modules/i3.c index 5e5c80a..0ed6927 100644 --- a/modules/i3.c +++ b/modules/i3.c @@ -878,9 +878,9 @@ static bool verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { - {"spacing", false, &conf_verify_int}, - {"left-spacing", false, &conf_verify_int}, - {"right-spacing", false, &conf_verify_int}, + {"spacing", false, &conf_verify_unsigned}, + {"left-spacing", false, &conf_verify_unsigned}, + {"right-spacing", false, &conf_verify_unsigned}, {"sort", false, &verify_sort}, {"persistent", false, &verify_persistent}, {"content", true, &verify_content}, diff --git a/modules/mpd.c b/modules/mpd.c index bebd401..274fdc8 100644 --- a/modules/mpd.c +++ b/modules/mpd.c @@ -616,7 +616,7 @@ verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { {"host", true, &conf_verify_string}, - {"port", false, &conf_verify_int}, + {"port", false, &conf_verify_unsigned}, MODULE_COMMON_ATTRS, }; diff --git a/modules/network.c b/modules/network.c index 06ada9b..3bff716 100644 --- a/modules/network.c +++ b/modules/network.c @@ -1257,7 +1257,7 @@ verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { {"name", true, &conf_verify_string}, - {"poll-interval", false, &conf_verify_int}, + {"poll-interval", false, &conf_verify_unsigned}, MODULE_COMMON_ATTRS, }; diff --git a/modules/removables.c b/modules/removables.c index 04d2695..3a54379 100644 --- a/modules/removables.c +++ b/modules/removables.c @@ -652,9 +652,9 @@ static bool verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { - {"spacing", false, &conf_verify_int}, - {"left-spacing", false, &conf_verify_int}, - {"right-spacing", false, &conf_verify_int}, + {"spacing", false, &conf_verify_unsigned}, + {"left-spacing", false, &conf_verify_unsigned}, + {"right-spacing", false, &conf_verify_unsigned}, {"ignore", false, &verify_ignore}, MODULE_COMMON_ATTRS, }; diff --git a/modules/script.c b/modules/script.c index 2ddd722..254aac4 100644 --- a/modules/script.c +++ b/modules/script.c @@ -709,7 +709,7 @@ verify_conf(keychain_t *chain, const struct yml_node *node) static const struct attr_info attrs[] = { {"path", true, &conf_verify_path}, {"args", false, &conf_verify_args}, - {"poll-interval", false, &conf_verify_int}, + {"poll-interval", false, &conf_verify_unsigned}, MODULE_COMMON_ATTRS, }; diff --git a/modules/sway-xkb.c b/modules/sway-xkb.c index f4e7577..9841feb 100644 --- a/modules/sway-xkb.c +++ b/modules/sway-xkb.c @@ -374,9 +374,9 @@ static bool verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { - {"spacing", false, &conf_verify_int}, - {"left-spacing", false, &conf_verify_int}, - {"right-spacing", false, &conf_verify_int}, + {"spacing", false, &conf_verify_unsigned}, + {"left-spacing", false, &conf_verify_unsigned}, + {"right-spacing", false, &conf_verify_unsigned}, {"identifiers", true, &verify_identifiers}, MODULE_COMMON_ATTRS, }; diff --git a/particle.h b/particle.h index 4ca520f..7c5685e 100644 --- a/particle.h +++ b/particle.h @@ -76,12 +76,12 @@ void exposable_default_on_mouse( enum mouse_event event, enum mouse_button btn, int x, int y); /* List of attributes *all* particles implement */ -#define PARTICLE_COMMON_ATTRS \ - {"margin", false, &conf_verify_int}, \ - {"left-margin", false, &conf_verify_int}, \ - {"right-margin", false, &conf_verify_int}, \ - {"on-click", false, &conf_verify_on_click}, \ - {"font", false, &conf_verify_font}, \ - {"foreground", false, &conf_verify_color}, \ - {"deco", false, &conf_verify_decoration}, \ +#define PARTICLE_COMMON_ATTRS \ + {"margin", false, &conf_verify_unsigned}, \ + {"left-margin", false, &conf_verify_unsigned}, \ + {"right-margin", false, &conf_verify_unsigned}, \ + {"on-click", false, &conf_verify_on_click}, \ + {"font", false, &conf_verify_font}, \ + {"foreground", false, &conf_verify_color}, \ + {"deco", false, &conf_verify_decoration}, \ {NULL, false, NULL} diff --git a/particles/list.c b/particles/list.c index 19ff15b..e5cf883 100644 --- a/particles/list.c +++ b/particles/list.c @@ -208,9 +208,9 @@ verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { {"items", true, &conf_verify_particle_list_items}, - {"spacing", false, &conf_verify_int}, - {"left-spacing", false, &conf_verify_int}, - {"right-spacing", false, &conf_verify_int}, + {"spacing", false, &conf_verify_unsigned}, + {"left-spacing", false, &conf_verify_unsigned}, + {"right-spacing", false, &conf_verify_unsigned}, PARTICLE_COMMON_ATTRS, }; diff --git a/particles/progress-bar.c b/particles/progress-bar.c index ebc51c3..462d536 100644 --- a/particles/progress-bar.c +++ b/particles/progress-bar.c @@ -323,7 +323,7 @@ verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { {"tag", true, &conf_verify_string}, - {"length", true, &conf_verify_int}, + {"length", true, &conf_verify_unsigned}, /* TODO: make these optional? Default to empty */ {"start", true, &conf_verify_particle}, {"end", true, &conf_verify_particle}, diff --git a/particles/string.c b/particles/string.c index c475d5b..f6083f6 100644 --- a/particles/string.c +++ b/particles/string.c @@ -323,7 +323,7 @@ verify_conf(keychain_t *chain, const struct yml_node *node) { static const struct attr_info attrs[] = { {"text", true, &conf_verify_string}, - {"max", false, &conf_verify_int}, + {"max", false, &conf_verify_unsigned}, PARTICLE_COMMON_ATTRS, };