Check for overflow before it occurs. Also add check for
negative numbers. Suggested by: ache Approved by: kib (mentor)
This commit is contained in:
parent
60ae52f785
commit
02fc66090b
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=209392
@ -139,7 +139,7 @@ g_parse_lba(const char *lbastr, unsigned sectorsize, off_t *sectors)
|
|||||||
assert(sectors != NULL);
|
assert(sectors != NULL);
|
||||||
|
|
||||||
number = (off_t)strtoimax(lbastr, &s, 0);
|
number = (off_t)strtoimax(lbastr, &s, 0);
|
||||||
if (s == lbastr)
|
if (s == lbastr || number < 0)
|
||||||
return (EINVAL);
|
return (EINVAL);
|
||||||
|
|
||||||
mult = 1;
|
mult = 1;
|
||||||
@ -187,7 +187,7 @@ g_parse_lba(const char *lbastr, unsigned sectorsize, off_t *sectors)
|
|||||||
if (*s != '\0')
|
if (*s != '\0')
|
||||||
return (EINVAL);
|
return (EINVAL);
|
||||||
done:
|
done:
|
||||||
if (mult * unit < mult || number * mult * unit < number)
|
if ((OFF_MAX / unit) < mult || (OFF_MAX / mult / unit) < number)
|
||||||
return (ERANGE);
|
return (ERANGE);
|
||||||
number *= mult * unit;
|
number *= mult * unit;
|
||||||
if (number % sectorsize)
|
if (number % sectorsize)
|
||||||
|
Loading…
Reference in New Issue
Block a user