From: Florian Forster Date: Sun, 31 Oct 2010 14:44:18 +0000 (+0100) Subject: src/common.c: parse_values: Add error handling. X-Git-Tag: collectd-5.0.0-beta0~19^2~10 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=1beb6992bd5132cd98b293051b14abc7f2718842;p=collectd.git src/common.c: parse_values: Add error handling. --- diff --git a/src/common.c b/src/common.c index 1cef5e17..87d7bf08 100644 --- a/src/common.c +++ b/src/common.c @@ -981,8 +981,20 @@ int parse_values (char *buffer, value_list_t *vl, const data_set_t *ds) if (strcmp ("N", ptr) == 0) vl->time = cdtime (); else - /* FIXME: Add error checking here. */ - vl->time = DOUBLE_TO_CDTIME_T (atof (ptr)); + { + char *endptr = NULL; + double tmp; + + errno = 0; + tmp = strtod (ptr, &endptr); + if ((errno != 0) /* Overflow */ + || (endptr == ptr) /* Invalid string */ + || (endptr == NULL) /* This should not happen */ + || (*endptr != 0)) /* Trailing chars */ + return (-1); + + vl->time = DOUBLE_TO_CDTIME_T (tmp); + } } else {