0
votes

I have a program in C that was running perfectly in a debian box. I have been asked to compile and run it on CentOs 6.5. Everything compiles perfectly except the part where I try to get a value from a configuration file. Code is writen like this:

char config_file[150]="file.conf";
config_t cfg;
config_setting_t *ssl_xor_key;
char xkey[256];
ssl_xor_key = config_lookup(&cfg, "ssl.xor.key");
strcpy(xkey,config_setting_get_string(ssl_xor_key));

The config file contains this:

ssl:
{
    xor:
    {
        key="textexttextexttextext";
    };
};

When the program arrives to the config_setting_get_string it crashes. I have tried to just set the string in the strcpy command and it works. I have seen this on the /var/log/messages:

kernel: mysql-proxy[9808]: segfault at 8 ip 00007f3ba9d53d12 sp 00007f3baab8a0d8 error 4 in libconfig.so.8.0.0[7f3ba9d51000+a000]

I have seen that while the original Debian box had libconfig 1.4.9, CentOs most updated version is 1.3.2. I am not sure if the command is suported in that version, as I was not able to find the documentation of the old version.

I also have tried to compile the newest version on the Centos Box but I get errors on the process, so I think it is not suported.

Any idea of what can be the solution?

1
Perhaps you need to check the return value of config_lookup() before you blindly use it for something else. Also, cfg appears to be used uninitialized, and I don't see anything there that actually attempts to open a config file or anything, although I am admittedly completely unfamiliar with that particular API...twalberg
Thanks. I am going to try what you say. Would you recomend any alternative to the api for managing configuration files?jordi

1 Answers

0
votes

Looks like older version of libconfig are more sensitive to sintax errors in config files. I had mising the final ; on the file. Now it works.