ext2fs|ufs:Unsign some values related to allocation.

When allocating memory through malloc(9), we always expect the amount of
memory requested to be unsigned as a negative value would either stand for
an error or an overflow.
Unsign some values, found when considering the use of mallocarray(9), to
avoid unnecessary casting. Also consider that indexes should be of
at least the same size/type as the upper limit they pretend to index.

MFC after:	2 weeks
This commit is contained in:
Pedro F. Giffuni
2018-01-24 17:58:48 +00:00
parent 2128fefb75
commit a94a2945be
4 changed files with 6 additions and 4 deletions
+1 -1
View File
@@ -145,9 +145,9 @@ ext2_readdir(struct vop_readdir_args *ap)
off_t offset, startoffset; off_t offset, startoffset;
size_t readcnt, skipcnt; size_t readcnt, skipcnt;
ssize_t startresid; ssize_t startresid;
int ncookies;
int DIRBLKSIZ = VTOI(ap->a_vp)->i_e2fs->e2fs_bsize; int DIRBLKSIZ = VTOI(ap->a_vp)->i_e2fs->e2fs_bsize;
int error; int error;
u_int ncookies;
if (uio->uio_offset < 0) if (uio->uio_offset < 0)
return (EINVAL); return (EINVAL);
+2 -1
View File
@@ -2466,7 +2466,8 @@ softdep_mount(devvp, mp, fs, cred)
struct ufsmount *ump; struct ufsmount *ump;
struct cg *cgp; struct cg *cgp;
struct buf *bp; struct buf *bp;
int i, error, cyl; u_int cyl, i;
int error;
sdp = malloc(sizeof(struct mount_softdeps), M_MOUNTDATA, sdp = malloc(sizeof(struct mount_softdeps), M_MOUNTDATA,
M_WAITOK | M_ZERO); M_WAITOK | M_ZERO);
+2 -1
View File
@@ -349,7 +349,8 @@ ufsdirhash_build(struct inode *ip)
struct direct *ep; struct direct *ep;
struct vnode *vp; struct vnode *vp;
doff_t bmask, pos; doff_t bmask, pos;
int dirblocks, i, j, memreqd, nblocks, narrays, nslots, slot; u_int dirblocks, i, narrays, nblocks, nslots;
int j, memreqd, slot;
/* Take care of a decreased sysctl value. */ /* Take care of a decreased sysctl value. */
while (ufs_dirhashmem > ufs_dirhashmaxmem) { while (ufs_dirhashmem > ufs_dirhashmaxmem) {
+1 -1
View File
@@ -2170,7 +2170,7 @@ ufs_readdir(ap)
off_t offset, startoffset; off_t offset, startoffset;
size_t readcnt, skipcnt; size_t readcnt, skipcnt;
ssize_t startresid; ssize_t startresid;
int ncookies; u_int ncookies;
int error; int error;
if (uio->uio_offset < 0) if (uio->uio_offset < 0)