Avoid signed overflow in error handling code.

Reviewed by:	cperciva, bjk
This commit is contained in:
eadler 2013-05-21 19:56:03 +00:00
parent 4024f68eb0
commit b6bdb6d2f3

View File

@ -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");