diff options
author | ae <ae@FreeBSD.org> | 2010-06-21 12:50:54 +0000 |
---|---|---|
committer | ae <ae@FreeBSD.org> | 2010-06-21 12:50:54 +0000 |
commit | 1ae32ded9786b79f96b22b5c967453dce47c36e0 (patch) | |
tree | f42eece5392e92dc58c3f6163f638251d9d10d65 /sbin/geom/misc | |
parent | 76489ac1ea604f511232838164573ea21e9a74a8 (diff) | |
download | FreeBSD-src-1ae32ded9786b79f96b22b5c967453dce47c36e0.zip FreeBSD-src-1ae32ded9786b79f96b22b5c967453dce47c36e0.tar.gz |
Check for overflow before it occurs. Also add check for
negative numbers.
Suggested by: ache
Approved by: kib (mentor)
Diffstat (limited to 'sbin/geom/misc')
-rw-r--r-- | sbin/geom/misc/subr.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/sbin/geom/misc/subr.c b/sbin/geom/misc/subr.c index 7a4786f..5c6afe6 100644 --- a/sbin/geom/misc/subr.c +++ b/sbin/geom/misc/subr.c @@ -139,7 +139,7 @@ g_parse_lba(const char *lbastr, unsigned sectorsize, off_t *sectors) assert(sectors != NULL); number = (off_t)strtoimax(lbastr, &s, 0); - if (s == lbastr) + if (s == lbastr || number < 0) return (EINVAL); mult = 1; @@ -187,7 +187,7 @@ sfx: if (*s != '\0') return (EINVAL); done: - if (mult * unit < mult || number * mult * unit < number) + if ((OFF_MAX / unit) < mult || (OFF_MAX / mult / unit) < number) return (ERANGE); number *= mult * unit; if (number % sectorsize) |