diff options
author | Christian Hesse <mail@eworm.de> | 2015-06-24 12:09:20 +0200 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2015-06-24 12:09:20 +0200 |
commit | 39c234137f95dd378f55233abf4666bfa2e5f929 (patch) | |
tree | 0cb11c7d472fcac200bdbfcd6cb0d963e92d4257 | |
parent | ed8a9d94802615f703f38c55f65e3ccec1d4526f (diff) | |
download | pacredir-39c234137f95dd378f55233abf4666bfa2e5f929.tar.gz pacredir-39c234137f95dd378f55233abf4666bfa2e5f929.tar.zst |
fix string handling
iniparser_getstring() returns const char*, but strtok() modifies its
first argument. So strdup() and free().
-rw-r--r-- | pacredir.c | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -489,6 +489,7 @@ void sighup_callback(int signal) { /*** main ***/ int main(int argc, char ** argv) { dictionary * ini; + const char * inistring; char * values, * value; uint16_t port; struct ignore_interfaces * tmp_ignore_interfaces; @@ -532,7 +533,8 @@ int main(int argc, char ** argv) { /* continue anyway, there is nothing essential in the config file */ } else { /* store interfaces to ignore */ - if ((values = iniparser_getstring(ini, "general:ignore interfaces", NULL)) != NULL) { + if ((inistring = iniparser_getstring(ini, "general:ignore interfaces", NULL)) != NULL) { + values = strdup(inistring); tmp_ignore_interfaces = ignore_interfaces; value = strtok(values, DELIMITER); @@ -546,10 +548,12 @@ int main(int argc, char ** argv) { } tmp_ignore_interfaces->interface = NULL; tmp_ignore_interfaces->next = NULL; + free(values); } /* add static pacserve hosts */ - if ((values = iniparser_getstring(ini, "general:pacserve hosts", NULL)) != NULL) { + if ((inistring = iniparser_getstring(ini, "general:pacserve hosts", NULL)) != NULL) { + values = strdup(inistring); value = strtok(values, DELIMITER); while (value != NULL) { if (verbose > 0) @@ -563,10 +567,12 @@ int main(int argc, char ** argv) { add_host(value, port, PACSERVE); value = strtok(NULL, DELIMITER); } + free(values); } /* add static pacdbserve hosts */ - if ((values = iniparser_getstring(ini, "general:pacdbserve hosts", NULL)) != NULL) { + if ((inistring = iniparser_getstring(ini, "general:pacdbserve hosts", NULL)) != NULL) { + values = strdup(inistring); value = strtok(values, DELIMITER); while (value != NULL) { if (verbose > 0) @@ -580,6 +586,7 @@ int main(int argc, char ** argv) { add_host(value, port, PACDBSERVE); value = strtok(NULL, DELIMITER); } + free(values); } /* done reading config file, free */ |