Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use strtod, not atof, for parsing doubles in the configuration. #1316

Merged
merged 2 commits into from Sep 16, 2019

Conversation

Labels
None yet
Projects
None yet
4 participants
@nmathewson
Copy link
Contributor

@nmathewson nmathewson commented Sep 10, 2019

This lets us detect erroneous doubles, which previously we could not
do.

Fixes bug 31475; bugfix on commit 00a9e37, a.k.a svn:r136.

This lets us detect erroneous doubles, which previously we could not
do.

Fixes bug 31475; bugfix on commit 00a9e37, a.k.a svn:r136.
@coveralls
Copy link

@coveralls coveralls commented Sep 10, 2019

Pull Request Test Coverage Report for Build 6192

  • 10 of 10 (100.0%) changed or added relevant lines in 1 file are covered.
  • 528 unchanged lines in 6 files lost coverage.
  • Overall coverage increased (+0.06%) to 63.229%

Files with Coverage Reduction New Missed Lines %
src/feature/client/entrynodes.c 2 86.25%
src/lib/malloc/map_anon.c 4 88.24%
src/lib/err/torerr.c 13 82.93%
src/lib/log/util_bug.c 16 50.0%
src/lib/log/log.c 127 71.61%
src/app/config/config.c 366 73.67%
Totals Coverage Status
Change from base Build 6120: 0.06%
Covered Lines: 47852
Relevant Lines: 75680

💛 - Coveralls

return 0;
char *endptr=NULL;
*v = strtod(value, &endptr);
if (endptr == value || *endptr != '\0') {
Copy link
Contributor

@dgoulet-tor dgoulet-tor Sep 12, 2019

The endptr == value check I believe needs to be checked also along with v == 0. Man page:

If no conversion is performed, zero is returned and (unless endptr is
null) the value of nptr is stored in the location referenced by endptr.

The other thing I would probably look for is the overflow situation? It is a bit unclear if this current check would catch that (endptr == value) but manpage gives us clear values to look at in that case:

   If the correct value would  cause  overflow,  plus  or  minus  HUGE_VAL
   (HUGE_VALF,  HUGE_VALL)  is  returned  (according  to  the  sign of the
   value), and ERANGE is stored in errno. If  the  correct  value  would
   cause underflow, zero is returned and ERANGE is stored in errno.

Any floating point value too positive or negative to distinguish
from +/-Inf, or too small to distinguish from +/-0, is an
over/underflow.
@torproject-pusher torproject-pusher merged commit bfc5f09 into torproject:master Sep 16, 2019
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment