From a7d0e609ed954c58b3bd3b2708bb28fb2a7cf80f Mon Sep 17 00:00:00 2001 From: Robert Schmidt <robert.schmidt@openairinterface.org> Date: Wed, 27 Nov 2024 16:58:00 +0100 Subject: [PATCH] config module: check that memory is enough, allow more restarts A later commit implements the "restart" of the L1. The L1 reads configuration options. First, allow to re-read configurations by increasing the amount of memory the config module might allocate. Then, avoid an out-of-bound write by checking that we still have memory available (and assert if not possible). --- common/config/config_common.c | 1 + common/config/config_load_configmodule.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/common/config/config_common.c b/common/config/config_common.c index d6e499b6a8c..2bca71d912e 100644 --- a/common/config/config_common.c +++ b/common/config/config_common.c @@ -108,6 +108,7 @@ void *config_allocate_new(configmodule_interface_t *cfg, int sz, bool autoFree) // add the memory piece in the managed memory pieces list pthread_mutex_lock(&cfg->memBlocks_mutex); int newBlockIdx=cfg->numptrs++; + AssertFatal(newBlockIdx < sizeofArray(cfg->oneBlock), "reached maximum number of dynamically allocatable blocks\n"); oneBlock_t* tmp=&cfg->oneBlock[newBlockIdx]; tmp->ptrs = (char *)ptr; tmp->ptrsAllocated = true; diff --git a/common/config/config_load_configmodule.h b/common/config/config_load_configmodule.h index bc383228052..3ec27d456f2 100644 --- a/common/config/config_load_configmodule.h +++ b/common/config/config_load_configmodule.h @@ -41,7 +41,7 @@ #include "common/config/config_paramdesc.h" #include "common/utils/T/T.h" #define CONFIG_MAX_OOPT_PARAMS 10 // maximum number of parameters in the -O option (-O <cfgmode>:P1:P2... -#define CONFIG_MAX_ALLOCATEDPTRS 2048 // maximum number of parameters that can be dynamicaly allocated in the config module +#define CONFIG_MAX_ALLOCATEDPTRS 32768 // maximum number of parameters that can be dynamicaly allocated in the config module /* default values for configuration module parameters */ #define CONFIG_LIBCONFIGFILE "libconfig" // use libconfig file -- GitLab