From: Florian Forster Date: Tue, 8 Dec 2015 13:22:54 +0000 (+0100) Subject: rrdtool plugin: Improve handling of the "DataDir" option. X-Git-Tag: collectd-5.5.1~13^2~7 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=4ef7c074cdbab9c43cbbfcb918e9ba4f6be6fa1e;p=collectd.git rrdtool plugin: Improve handling of the "DataDir" option. CID: 37977 --- diff --git a/src/rrdtool.c b/src/rrdtool.c index 9b5723ad..9b04d10e 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -1008,23 +1008,32 @@ static int rrd_config (const char *key, const char *value) } else if (strcasecmp ("DataDir", key) == 0) { - if (datadir != NULL) - free (datadir); - datadir = strdup (value); - if (datadir != NULL) + char *tmp; + size_t len; + + tmp = strdup (value); + if (tmp == NULL) { - int len = strlen (datadir); - while ((len > 0) && (datadir[len - 1] == '/')) - { - len--; - datadir[len] = '\0'; - } - if (len <= 0) - { - free (datadir); - datadir = NULL; - } + ERROR ("rrdtool plugin: strdup failed."); + return (1); + } + + len = strlen (datadir); + while ((len > 0) && (datadir[len - 1] == '/')) + { + len--; + datadir[len] = 0; } + + if (len == 0) + { + ERROR ("rrdtool plugin: Invalid \"DataDir\" option."); + sfree (tmp); + return (1); + } + + sfree (datadir); + datadir = tmp; } else if (strcasecmp ("StepSize", key) == 0) {