Add asserts to prevent overflows of c_addr.

Add some asserts that prevents the overflows of c_addr. This can't
happen, absent bugs. However, certain large filesystems can cause
problems. These have been prevented by r334968, but a solution
is needed. These asserts will help assure that solution is correct.

PR: 228807
Reviewed by: db
This commit is contained in:
Warner Losh 2018-06-11 19:32:36 +00:00
parent 803fec5fdf
commit 2d518c6518
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=334969
2 changed files with 6 additions and 0 deletions

View File

@ -47,6 +47,7 @@ static const char rcsid[] =
#include <protocols/dumprestore.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
@ -279,6 +280,7 @@ flushtape(void)
blks = 0;
if (spcl.c_type != TS_END) {
assert(spcl.c_count <= TP_NINDIR);
for (i = 0; i < spcl.c_count; i++)
if (spcl.c_addr[i] != 0)
blks++;

View File

@ -46,6 +46,7 @@ static const char rcsid[] =
#include <protocols/dumprestore.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
@ -637,6 +638,7 @@ ufs1_blksout(ufs1_daddr_t *blkp, int frags, ino_t ino)
count = blks;
else
count = i + TP_NINDIR;
assert(count <= TP_NINDIR + i);
for (j = i; j < count; j++)
if (blkp[j / tbperdb] != 0)
spcl.c_addr[j - i] = 1;
@ -689,6 +691,7 @@ ufs2_blksout(union dinode *dp, ufs2_daddr_t *blkp, int frags, ino_t ino,
count = blks;
else
count = i + TP_NINDIR;
assert(count <= TP_NINDIR + i);
for (j = i; j < count; j++)
if (blkp[j / tbperdb] != 0)
spcl.c_addr[j - i] = 1;
@ -753,6 +756,7 @@ appendextdata(union dinode *dp)
* data by the writeextdata() routine.
*/
tbperdb = sblock->fs_bsize >> tp_bshift;
assert(spcl.c_count + blks < TP_NINDIR);
for (i = 0; i < blks; i++)
if (&dp->dp2.di_extb[i / tbperdb] != 0)
spcl.c_addr[spcl.c_count + i] = 1;