mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2025-01-27 10:24:22 +03:00
libzfs: Fix bounds checks for float parsing
UINT64_MAX is not exactly representable as a double. The closest representation is UINT64_MAX + 1, so we can use a >= comparison instead of > for the bounds check. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Ryan Moeller <ryan@iXsystems.com> Closes #10127
This commit is contained in:
parent
7261fc2e81
commit
4d32abaa87
@ -648,7 +648,12 @@ nicenumtoull(const char *buf)
|
|||||||
} else if (end[0] == '.') {
|
} else if (end[0] == '.') {
|
||||||
double fval = strtod(buf, &end);
|
double fval = strtod(buf, &end);
|
||||||
fval *= pow(2, str2shift(end));
|
fval *= pow(2, str2shift(end));
|
||||||
if (fval > UINT64_MAX) {
|
/*
|
||||||
|
* UINT64_MAX is not exactly representable as a double.
|
||||||
|
* The closest representation is UINT64_MAX + 1, so we
|
||||||
|
* use a >= comparison instead of > for the bounds check.
|
||||||
|
*/
|
||||||
|
if (fval >= (double)UINT64_MAX) {
|
||||||
(void) fprintf(stderr, "ztest: value too large: %s\n",
|
(void) fprintf(stderr, "ztest: value too large: %s\n",
|
||||||
buf);
|
buf);
|
||||||
usage(B_FALSE);
|
usage(B_FALSE);
|
||||||
|
@ -1411,7 +1411,12 @@ zfs_nicestrtonum(libzfs_handle_t *hdl, const char *value, uint64_t *num)
|
|||||||
|
|
||||||
fval *= pow(2, shift);
|
fval *= pow(2, shift);
|
||||||
|
|
||||||
if (fval > UINT64_MAX) {
|
/*
|
||||||
|
* UINT64_MAX is not exactly representable as a double.
|
||||||
|
* The closest representation is UINT64_MAX + 1, so we
|
||||||
|
* use a >= comparison instead of > for the bounds check.
|
||||||
|
*/
|
||||||
|
if (fval >= (double)UINT64_MAX) {
|
||||||
if (hdl)
|
if (hdl)
|
||||||
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
|
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
|
||||||
"numeric value is too large"));
|
"numeric value is too large"));
|
||||||
|
Loading…
Reference in New Issue
Block a user