From 4ef7c074cdbab9c43cbbfcb918e9ba4f6be6fa1e Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Tue, 8 Dec 2015 14:22:54 +0100 Subject: [PATCH] rrdtool plugin: Improve handling of the "DataDir" option. CID: 37977 --- src/rrdtool.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) 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) { -- 2.30.2