From 39c234137f95dd378f55233abf4666bfa2e5f929 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 24 Jun 2015 12:09:20 +0200 Subject: fix string handling iniparser_getstring() returns const char*, but strtok() modifies its first argument. So strdup() and free(). --- pacredir.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pacredir.c b/pacredir.c index feefa54..8ab2127 100644 --- a/pacredir.c +++ b/pacredir.c @@ -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 */ -- cgit v1.2.3-54-g00ecf