diff --git a/modules/type/dag/dap_chain_cs_dag.c b/modules/type/dag/dap_chain_cs_dag.c index 6bb75e5b6fb4710f1b7c8e1384f96f4cb22ec153..4d18c349e988c130078bfdd1b5da1c7d80874928 100644 --- a/modules/type/dag/dap_chain_cs_dag.c +++ b/modules/type/dag/dap_chain_cs_dag.c @@ -664,18 +664,26 @@ static bool s_chain_callback_datums_pool_proc(dap_chain_t *a_chain, dap_chain_da size_t l_hashes_size = l_dag->is_single_line ? 1 : l_dag->datum_add_hashes_count, l_hashes_linked = 0; + if (!l_hashes_size) { + log_it(L_ERROR, "Configuration mismatch, no hashed to be linked", l_datum_hash_str); + return false; + } dap_chain_hash_fast_t *l_hashes = l_hashes_size ? DAP_NEW_STACK_SIZE(dap_chain_hash_fast_t, l_hashes_size * sizeof(dap_chain_hash_fast_t)) : NULL; + if (!l_hashes) { + log_it(L_CRITICAL, "Stack limit reached"); + return false; + } /* Prepare round */ - if (l_hashes && l_hashes_size) { - pthread_mutex_lock(&PVT(l_dag)->events_mutex); - if (!HASH_COUNT(PVT(l_dag)->events_lasts_unlinked)) { - pthread_mutex_unlock(&PVT(l_dag)->events_mutex); - log_it(L_INFO, "Nothing to link"); + pthread_mutex_lock(&PVT(l_dag)->events_mutex); + if (!HASH_COUNT(PVT(l_dag)->events_lasts_unlinked)) { + pthread_mutex_unlock(&PVT(l_dag)->events_mutex); + log_it(L_INFO, "Nothing to link"); + if (!l_seed_mode) return false; - } + } else { /* We'll use modification-safe iteration thru the additional hashtable thus the chosen events will not repeat */ #define always_true(ev) true dap_chain_cs_dag_event_item_t *l_tmp = NULL, *l_cur_ev, *l_tmp_ev;