Date: Wed, 10 Jan 2018 19:45:38 +0000 (UTC) From: "Pedro F. Giffuni" <pfg@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r327781 - head/sys/ufs/ufs Message-ID: <201801101945.w0AJjc7C081888@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: pfg Date: Wed Jan 10 19:45:38 2018 New Revision: 327781 URL: https://svnweb.freebsd.org/changeset/base/327781 Log: Use mallocarray(9) in dirhash. Basic use of mallocarray to prevent overflows. Here allocation is done with M_NOWAIT so the code is prepared for the possibility of returning NULL values. Since mallocarray expects unsigned parameters, unsign some related variables to minimize sign conversions. Reviewed by: mckusick Modified: head/sys/ufs/ufs/ufs_dirhash.c Modified: head/sys/ufs/ufs/ufs_dirhash.c ============================================================================== --- head/sys/ufs/ufs/ufs_dirhash.c Wed Jan 10 19:41:05 2018 (r327780) +++ head/sys/ufs/ufs/ufs_dirhash.c Wed Jan 10 19:45:38 2018 (r327781) @@ -349,7 +349,8 @@ ufsdirhash_build(struct inode *ip) struct direct *ep; struct vnode *vp; doff_t bmask, pos; - int dirblocks, i, j, memreqd, nblocks, narrays, nslots, slot; + int j, memreqd, slot; + u_int dirblocks, i, nblocks, narrays, nslots; /* Take care of a decreased sysctl value. */ while (ufs_dirhashmem > ufs_dirhashmaxmem) { @@ -415,11 +416,11 @@ ufsdirhash_build(struct inode *ip) * Use non-blocking mallocs so that we will revert to a linear * lookup on failure rather than potentially blocking forever. */ - dh->dh_hash = malloc(narrays * sizeof(dh->dh_hash[0]), + dh->dh_hash = mallocarray(narrays, sizeof(dh->dh_hash[0]), M_DIRHASH, M_NOWAIT | M_ZERO); if (dh->dh_hash == NULL) goto fail; - dh->dh_blkfree = malloc(nblocks * sizeof(dh->dh_blkfree[0]), + dh->dh_blkfree = mallocarray(nblocks, sizeof(dh->dh_blkfree[0]), M_DIRHASH, M_NOWAIT); if (dh->dh_blkfree == NULL) goto fail;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201801101945.w0AJjc7C081888>