Avoid signed overflow in error handling code.
Reviewed by: cperciva, bjk
This commit is contained in:
parent
4024f68eb0
commit
b6bdb6d2f3
@ -379,8 +379,10 @@ newfile(void)
|
||||
|
||||
/* maxfiles = pattlen^sufflen, but don't use libm. */
|
||||
for (maxfiles = 1, i = 0; i < sufflen; i++)
|
||||
if ((maxfiles *= pattlen) <= 0)
|
||||
if (LONG_MAX / pattlen < maxfiles)
|
||||
errx(EX_USAGE, "suffix is too long (max %ld)", i);
|
||||
else
|
||||
maxfiles *= pattlen;
|
||||
|
||||
if (fnum == maxfiles)
|
||||
errx(EX_DATAERR, "too many files");
|
||||
|
Loading…
Reference in New Issue
Block a user