Merge remote-tracking branch 'origin/string_libconfig_fix' into integration_2026_w06 (!3898)
Fix config_libconfig_get for string Change in libconfig reading input for string to reject if it is not of type string with an error message
This commit is contained in:
@@ -319,6 +319,32 @@ int config_libconfig_set(configmodule_interface_t *cfg, paramdef_t *cfgoptions,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *config_type_to_name(int type)
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
case CONFIG_TYPE_NONE:
|
||||||
|
return "none";
|
||||||
|
case CONFIG_TYPE_GROUP:
|
||||||
|
return "group";
|
||||||
|
case CONFIG_TYPE_INT:
|
||||||
|
return "integer";
|
||||||
|
case CONFIG_TYPE_INT64:
|
||||||
|
return "64-bit integer";
|
||||||
|
case CONFIG_TYPE_FLOAT:
|
||||||
|
return "float";
|
||||||
|
case CONFIG_TYPE_STRING:
|
||||||
|
return "string";
|
||||||
|
case CONFIG_TYPE_BOOL:
|
||||||
|
return "boolean";
|
||||||
|
case CONFIG_TYPE_ARRAY:
|
||||||
|
return "array";
|
||||||
|
case CONFIG_TYPE_LIST:
|
||||||
|
return "list";
|
||||||
|
default:
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int config_libconfig_get(configmodule_interface_t *cfg, paramdef_t *cfgoptions, int numoptions, char *prefix)
|
int config_libconfig_get(configmodule_interface_t *cfg, paramdef_t *cfgoptions, int numoptions, char *prefix)
|
||||||
{
|
{
|
||||||
config_setting_t *setting;
|
config_setting_t *setting;
|
||||||
@@ -348,17 +374,26 @@ int config_libconfig_get(configmodule_interface_t *cfg, paramdef_t *cfgoptions,
|
|||||||
|
|
||||||
switch(cfgoptions[i].type) {
|
switch(cfgoptions[i].type) {
|
||||||
case TYPE_STRING:
|
case TYPE_STRING:
|
||||||
if ( config_lookup_string(&(libconfig_privdata.cfg), cfgpath, (const char**)&str)) {
|
setting = config_lookup(&(libconfig_privdata.cfg), cfgpath);
|
||||||
config_check_valptr(cfg, &cfgoptions[i], 1, strlen(str) + 1);
|
if (setting != NULL) {
|
||||||
if ( strlen(str)+1 > cfgoptions[i].numelt )
|
int type = config_setting_type(setting);
|
||||||
fprintf(stderr,"[LIBCONFIG] %s: %s exceeds maximum length of %i bytes, value truncated\n",
|
if (type == CONFIG_TYPE_STRING) {
|
||||||
cfgpath,str,cfgoptions[i].numelt);
|
const char *strng = config_setting_get_string(setting);
|
||||||
snprintf( *cfgoptions[i].strptr , cfgoptions[i].numelt, "%s", str);
|
config_check_valptr(cfg, &cfgoptions[i], 1, strlen(strng) + 1);
|
||||||
printf_params(cfg, "[LIBCONFIG] %s: \"%s\"\n", cfgpath, *cfgoptions[i].strptr);
|
if (strlen(strng) + 1 > cfgoptions[i].numelt)
|
||||||
} else {
|
fprintf(stderr,
|
||||||
|
"[LIBCONFIG] %s: %s exceeds maximum length of %i bytes, value truncated\n",
|
||||||
|
cfgpath,
|
||||||
|
strng,
|
||||||
|
cfgoptions[i].numelt);
|
||||||
|
snprintf(*cfgoptions[i].strptr, cfgoptions[i].numelt, "%s", strng);
|
||||||
|
printf_params(cfg, "[LIBCONFIG] %s: \"%s\"\n", cfgpath, *cfgoptions[i].strptr);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr,"[LIBCONFIG] expected a string input for %s but got type %s\n", cfgpath, config_type_to_name(type));
|
||||||
|
fatalerror = 1;
|
||||||
|
}
|
||||||
|
} else
|
||||||
defval = config_common_getdefault(cfg, &cfgoptions[i], prefix);
|
defval = config_common_getdefault(cfg, &cfgoptions[i], prefix);
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TYPE_STRINGLIST:
|
case TYPE_STRINGLIST:
|
||||||
|
|||||||
Reference in New Issue
Block a user