Log warning if configuration max settings is exceeded

+ snprintf instead of strncpy (null termination)
This commit is contained in:
SilentException committed 2025-02-24 21:35:02 +01:00
1 parent 8b0b75d4ad
commit 60b8e3b49e
1 file changed
+6 -1
+6 -1
View File
@@ -34,6 +34,7 @@ struct configentry {
} settings[CONFIG_MAX_SETTINGS];
static s32 numSettings = 0;
static u8 configMaxWarningLogged = 0;
static inline s32 configClampInt(s32 val, s32 min, s32 max)
{
@@ -64,11 +65,15 @@ static inline struct configentry *configAddEntry(const char *key)
{
if (numSettings < CONFIG_MAX_SETTINGS) {
struct configentry *cfg = &settings[numSettings++];
strncpy(cfg->key, key, CONFIG_MAX_KEYNAME);
snprintf(cfg->key, CONFIG_MAX_KEYNAME, "%s", key);
const char *delim = strrchr(cfg->key, '.');
cfg->seclen = delim ? (delim - cfg->key) : 0;
return cfg;
}
if (!configMaxWarningLogged) {
sysLogPrintf(LOG_WARNING, "Maximum number of configuration entries exceeded: %d", CONFIG_MAX_SETTINGS);
configMaxWarningLogged = 1;
}
return NULL;
}