return item->allowed_ids.dyn.n;
}
else {
- while (item->forbidden_ids.st[cnt] != 0) {
+ while (item->forbidden_ids.st[cnt] != 0 && cnt < G_N_ELEMENTS (item->allowed_ids.st)) {
cnt ++;
-
- g_assert (cnt < G_N_ELEMENTS (item->allowed_ids.st));
}
*nids = cnt;
}
}
-/* Usable for near-sorted ids list */
+/* Insertion sort: usable for near-sorted ids list */
static inline void
rspamd_ids_insertion_sort (guint *a, guint n)
{
if (ls->st[0] == -1) {
/* Dynamic array */
if (ls->dyn.len < ls->dyn.allocated) {
- /* Trivial, append + qsort */
+ /* Trivial, append + sort */
ls->dyn.n[ls->dyn.len++] = id;
}
else {
}
else {
/* Static part */
- while (ls->st[cnt] != 0) {
+ while (ls->st[cnt] != 0 && cnt < G_N_ELEMENTS (ls->st)) {
cnt ++;
}
return 0;
}
+static inline bool
+rspamd_lua_config_check_settings_symbols_object (const ucl_object_t *obj)
+{
+ if (obj == NULL) {
+ /* Semantically valid */
+ return true;
+ }
+
+ if (ucl_object_type (obj) == UCL_OBJECT) {
+ /* Key-value mapping - should be okay */
+ return true;
+ }
+
+ if (ucl_object_type (obj) == UCL_ARRAY) {
+ /* Okay if empty */
+ if (obj->len == 0) {
+ return true;
+ }
+ }
+
+ /* Everything else not okay */
+ return false;
+}
+
static gint
lua_config_register_settings_id (lua_State *L)
{
sym_enabled = ucl_object_lua_import (L, 3);
- if (sym_enabled != NULL && ucl_object_type (sym_enabled) != UCL_OBJECT) {
+ if (!rspamd_lua_config_check_settings_symbols_object (sym_enabled)) {
ucl_object_unref (sym_enabled);
return luaL_error (L, "invalid symbols enabled");
sym_disabled = ucl_object_lua_import (L, 4);
- if (sym_disabled != NULL && ucl_object_type (sym_disabled) != UCL_OBJECT) {
+ if (!rspamd_lua_config_check_settings_symbols_object (sym_disabled)) {
ucl_object_unref (sym_enabled);
ucl_object_unref (sym_disabled);