summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2015-06-24 12:09:20 +0200
committerGravatar Christian Hesse <mail@eworm.de>2015-06-24 12:09:20 +0200
commit39c234137f95dd378f55233abf4666bfa2e5f929 (patch)
tree0cb11c7d472fcac200bdbfcd6cb0d963e92d4257
parented8a9d94802615f703f38c55f65e3ccec1d4526f (diff)
downloadpaccache-39c234137f95dd378f55233abf4666bfa2e5f929.tar.gz
paccache-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.c13
1 files 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 */