diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2018-07-07 09:59:35 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2018-07-07 09:59:35 +0000 |
commit | 88b94d2f40b3ac498a6ecacd527ad64a456ff589 (patch) | |
tree | 7dff99cdeef1de1ce112e6e3cef7fe5ab94a78a1 /sbin/disklabel | |
parent | 9bc5a46a7901cbfbde1b4ba31ae3f92e4593f4b4 (diff) |
Add recommended error checks around the use of strtod() in
parse_sizespec().
ok otto@
Diffstat (limited to 'sbin/disklabel')
-rw-r--r-- | sbin/disklabel/editor.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c index 6cc72e1d198..b66345425ac 100644 --- a/sbin/disklabel/editor.c +++ b/sbin/disklabel/editor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: editor.c,v 1.337 2018/07/03 11:56:52 krw Exp $ */ +/* $OpenBSD: editor.c,v 1.338 2018/07/07 09:59:34 krw Exp $ */ /* * Copyright (c) 1997-2000 Todd C. Miller <Todd.Miller@courtesan.com> @@ -2472,9 +2472,12 @@ apply_unit(double val, u_char unit, u_int64_t *n) int parse_sizespec(const char *buf, double *val, char **unit) { + errno = 0; *val = strtod(buf, unit); - if ((*val == 0 && *unit == buf) || *val <= 0) - return (-1); + if (errno == ERANGE || *val < 0 || *val > ULLONG_MAX) + return (-1); /* too big/small */ + if (*val == 0 && *unit == buf) + return (-1); /* No conversion performed. */ if (*unit != NULL && *unit[0] == '\0') *unit = NULL; return (0); |