diff options
author | George Kadianakis <desnacked@riseup.net> | 2019-09-16 15:22:18 +0300 |
---|---|---|
committer | George Kadianakis <desnacked@riseup.net> | 2019-09-16 15:22:18 +0300 |
commit | cd72850e08f39413d281a480a78f38838ddf42e9 (patch) | |
tree | fb7177a1107c50605c74741de99d97f5474089b4 /src/lib/confmgt | |
parent | 5ec751b38b6ea5b40dece321a2c673c6b7e9cf01 (diff) | |
parent | bfc5f09979d49867b373b9433edf37adce8c66dd (diff) | |
download | tor-cd72850e08f39413d281a480a78f38838ddf42e9.tar.gz tor-cd72850e08f39413d281a480a78f38838ddf42e9.zip |
Merge branch 'tor-github/pr/1316'
Diffstat (limited to 'src/lib/confmgt')
-rw-r--r-- | src/lib/confmgt/type_defs.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/lib/confmgt/type_defs.c b/src/lib/confmgt/type_defs.c index 324b62e56c..62c12fcddd 100644 --- a/src/lib/confmgt/type_defs.c +++ b/src/lib/confmgt/type_defs.c @@ -37,6 +37,7 @@ #include <stddef.h> #include <string.h> +#include <errno.h> ////// // CONFIG_TYPE_STRING @@ -283,8 +284,23 @@ double_parse(void *target, const char *value, char **errmsg, (void)params; (void)errmsg; double *v = (double*)target; - // XXXX This is the preexisting behavior, but we should detect errors here. - *v = atof(value); + char *endptr=NULL; + errno = 0; + *v = strtod(value, &endptr); + if (endptr == value || *endptr != '\0') { + // Either there are no converted characters, or there were some characters + // that didn't get converted. + tor_asprintf(errmsg, "Could not convert %s to a number.", escaped(value)); + return -1; + } + if (errno == ERANGE) { + // strtod will set errno to ERANGE on underflow or overflow. + bool underflow = -.00001 < *v && *v < .00001; + tor_asprintf(errmsg, + "%s is too %s to express as a floating-point number.", + escaped(value), underflow ? "small" : "large"); + return -1; + } return 0; } |