diff options
author | mckusick <mckusick@FreeBSD.org> | 2014-02-25 18:25:27 +0000 |
---|---|---|
committer | mckusick <mckusick@FreeBSD.org> | 2014-02-25 18:25:27 +0000 |
commit | 35025aadc87f305150fe2f5bf71280b17f4214a0 (patch) | |
tree | e821dac3ba6f9d3f73b0b9866c489cb394dfa72a /sbin/fsck_ffs | |
parent | 725aa10f4c42136e71e74137951aa0ea2c7eebca (diff) | |
download | FreeBSD-src-35025aadc87f305150fe2f5bf71280b17f4214a0.zip FreeBSD-src-35025aadc87f305150fe2f5bf71280b17f4214a0.tar.gz |
Arguments for malloc and calloc should be size_t, not int.
Use proper bounds check when trying to free cached memory.
Spotted by: Xin Li
Tested by: Dmitry Sivachenko
MFC after: 2 weeks
Diffstat (limited to 'sbin/fsck_ffs')
-rw-r--r-- | sbin/fsck_ffs/fsck.h | 4 | ||||
-rw-r--r-- | sbin/fsck_ffs/fsutil.c | 4 |
2 files changed, 5 insertions, 3 deletions
diff --git a/sbin/fsck_ffs/fsck.h b/sbin/fsck_ffs/fsck.h index a7b5961..c0ec651 100644 --- a/sbin/fsck_ffs/fsck.h +++ b/sbin/fsck_ffs/fsck.h @@ -369,7 +369,7 @@ int flushentry(void); * to get space. */ static inline void* -Malloc(int size) +Malloc(size_t size) { void *retval; @@ -384,7 +384,7 @@ Malloc(int size) * to get space. */ static inline void* -Calloc(int cnt, int size) +Calloc(size_t cnt, size_t size) { void *retval; diff --git a/sbin/fsck_ffs/fsutil.c b/sbin/fsck_ffs/fsutil.c index 4b44fd4..5fe09a0 100644 --- a/sbin/fsck_ffs/fsutil.c +++ b/sbin/fsck_ffs/fsutil.c @@ -225,7 +225,7 @@ cgget(int cg) struct cg *cgp; if (cgbufs == NULL) { - cgbufs = Calloc(sblock.fs_ncg, sizeof(struct bufarea)); + cgbufs = calloc(sblock.fs_ncg, sizeof(struct bufarea)); if (cgbufs == NULL) errx(EEXIT, "cannot allocate cylinder group buffers"); } @@ -254,6 +254,8 @@ flushentry(void) { struct bufarea *cgbp; + if (flushtries == sblock.fs_ncg || cgbufs == NULL) + return (0); cgbp = &cgbufs[flushtries++]; if (cgbp->b_un.b_cg == NULL) return (0); |