diff options
author | Radek Novacek <rnovacek@redhat.com> | 2014-03-25 10:15:18 +0100 |
---|---|---|
committer | Radek Novacek <rnovacek@redhat.com> | 2014-03-25 10:30:37 +0100 |
commit | a7d7b281342b24146133f132867b3e1da276e923 (patch) | |
tree | 3715a65fb0b2fbdff1188ce37bbdee6ea9edbb67 /src/openlmi.c | |
parent | 4982dd72dbb5c0441c2fe0e3e213cd25c0424ea7 (diff) | |
download | openlmi-providers-a7d7b281342b24146133f132867b3e1da276e923.tar.gz openlmi-providers-a7d7b281342b24146133f132867b3e1da276e923.tar.xz openlmi-providers-a7d7b281342b24146133f132867b3e1da276e923.zip |
Fix incorrect array length when reading provider config options
Use NULL terminated array instead of obtaining array length using sizeof
(which doesn't work in this case).
Diffstat (limited to 'src/openlmi.c')
-rw-r--r-- | src/openlmi.c | 47 |
1 files changed, 18 insertions, 29 deletions
diff --git a/src/openlmi.c b/src/openlmi.c index 9ea08e8..4355d59 100644 --- a/src/openlmi.c +++ b/src/openlmi.c @@ -56,7 +56,8 @@ static ConfigEntry _toplevel_config_defaults[] = { { "CIM", "Namespace", "root/cimv2" }, { "CIM", "SystemClassName", "PG_ComputerSystem" }, { "LOG", "Level", "ERROR" }, - { "LOG", "Stderr" , "false" } + { "LOG", "Stderr" , "false" }, + { NULL, NULL, NULL } }; #define TOPLEVEL_CONFIG_FILE "/etc/openlmi/openlmi.conf" @@ -176,6 +177,19 @@ bool lmi_read_config_boolean(const char *group, const char *key) return false; } +void read_config(GKeyFile *keyFile, const ConfigEntry *config_dict) +{ + while (config_dict != NULL && config_dict->group != NULL && config_dict->key != NULL) { + if (!g_key_file_has_key(keyFile, config_dict->group, + config_dict->key, NULL)) { + + g_key_file_set_value(keyFile, config_dict->group, config_dict->key, + config_dict->value); + } + config_dict++; + } +} + GKeyFile *parse_config(const char *provider_name, const ConfigEntry *provider_config_defaults) { GError *error = NULL; @@ -228,35 +242,10 @@ GKeyFile *parse_config(const char *provider_name, const ConfigEntry *provider_co // Fill in default values where nothing gets read from config file. // Provider-specific configs first - gsize len = 0; - if (provider_config_defaults != NULL) { - len = sizeof(provider_config_defaults) / sizeof(ConfigEntry); - } - for (i = 0; i < len; i++) { - if (!g_key_file_has_key(masterKeyFile, - provider_config_defaults[i].group, - provider_config_defaults[i].key, NULL)) { - - g_key_file_set_value(masterKeyFile, - provider_config_defaults[i].group, - provider_config_defaults[i].key, - provider_config_defaults[i].value); - } - } - + read_config(masterKeyFile, provider_config_defaults); // Top-level configs - len = sizeof(_toplevel_config_defaults)/sizeof(ConfigEntry); - for (i = 0; i < len; i++) { - if (!g_key_file_has_key(masterKeyFile, - _toplevel_config_defaults[i].group, - _toplevel_config_defaults[i].key, NULL)) { - - g_key_file_set_value(masterKeyFile, - _toplevel_config_defaults[i].group, - _toplevel_config_defaults[i].key, - _toplevel_config_defaults[i].value); - } - } + read_config(masterKeyFile, _toplevel_config_defaults); + free(providerconf); return masterKeyFile; } |