Merge branch 'config-unsigned-ints'

Closes #129
This commit is contained in:
Daniel Eklöf 2021-11-15 20:02:11 +01:00
commit 9f2197ca1c
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
18 changed files with 65 additions and 47 deletions

View file

@ -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

View file

@ -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);

View file

@ -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},
};

View file

@ -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,

View file

@ -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,
};

View file

@ -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,
};

View file

@ -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.

View file

@ -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,
};

View file

@ -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},

View file

@ -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,
};

View file

@ -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,
};

View file

@ -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,
};

View file

@ -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,
};

View file

@ -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,
};

View file

@ -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}

View file

@ -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,
};

View file

@ -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},

View file

@ -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,
};