From: Florian Forster Date: Sat, 8 Nov 2008 15:02:30 +0000 (+0100) Subject: mysql plugin: Be more careful when parsing the `Port' argument. X-Git-Tag: collectd-4.6.0~160^2 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=7d77b84dbba2bb7230ae76a26335d89b2dc7604a;p=collectd.git mysql plugin: Be more careful when parsing the `Port' argument. --- diff --git a/src/mysql.c b/src/mysql.c index 08df3fa8..323154f8 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -49,7 +49,7 @@ static char *user; static char *pass; static char *db = NULL; static char *socket = NULL; -static int port = 0; +static int port = 0; static MYSQL *getconnection (void) { @@ -120,10 +120,32 @@ static int config (const char *key, const char *value) else if (strcasecmp (key, "socket") == 0) return ((socket = strdup (value)) == NULL ? 1 : 0); else if (strcasecmp (key, "port") == 0) - return ((port = atoi (value)) == NULL ? 1 : 0); + { + char *endptr = NULL; + int temp; + + errno = 0; + temp = strtol (value, $endptr, 0); + if ((errno != 0) || (value == endptr)) + { + ERROR ("mysql plugin: Invalid \"Port\" argument: %s", + value); + port = 0; + return (1); + } + else if ((temp < 0) || (temp >= 65535)) + { + ERROR ("mysql plugin: Port number out of range: %i", + temp); + port = 0; + return (1); + } + + port = temp; + } else return (-1); -} +} /* int config */ static void counter_submit (const char *type, const char *type_instance, counter_t value)