From a2245cbf99d15a24605e355f26b7612895ae2287 Mon Sep 17 00:00:00 2001 From: Dmitry Eremin Date: Fri, 10 Oct 2014 20:55:00 +0400 Subject: [PATCH] LU-5577 obdclass: (*dt_index_page_build_t) arg nob to size_t Change the type accordant usage and check for correct input. Signed-off-by: Dmitry Eremin Change-Id: Ic80025e95eddbc9fb51efd83c54573e5f310bb0b Reviewed-on: http://review.whamcloud.com/12382 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: John L. Hammond Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- lustre/include/dt_object.h | 2 +- lustre/mdd/mdd_object.c | 7 +++++-- lustre/obdclass/dt_object.c | 16 ++++++++++------ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lustre/include/dt_object.h b/lustre/include/dt_object.h index 90f8cb5..a54157e 100644 --- a/lustre/include/dt_object.h +++ b/lustre/include/dt_object.h @@ -2069,7 +2069,7 @@ int dt_record_read(const struct lu_env *env, struct dt_object *dt, int dt_record_write(const struct lu_env *env, struct dt_object *dt, const struct lu_buf *buf, loff_t *pos, struct thandle *th); typedef int (*dt_index_page_build_t)(const struct lu_env *env, - union lu_page *lp, int nob, + union lu_page *lp, size_t nob, const struct dt_it_ops *iops, struct dt_it *it, __u32 attr, void *arg); int dt_index_walk(const struct lu_env *env, struct dt_object *obj, diff --git a/lustre/mdd/mdd_object.c b/lustre/mdd/mdd_object.c index 6504da2..f1d78f1 100644 --- a/lustre/mdd/mdd_object.c +++ b/lustre/mdd/mdd_object.c @@ -1850,7 +1850,7 @@ static int mdd_readpage_sanity_check(const struct lu_env *env, } static int mdd_dir_page_build(const struct lu_env *env, union lu_page *lp, - int nob, const struct dt_it_ops *iops, + size_t nob, const struct dt_it_ops *iops, struct dt_it *it, __u32 attr, void *arg) { struct lu_dirpage *dp = &lp->lp_dir; @@ -1862,6 +1862,9 @@ static int mdd_dir_page_build(const struct lu_env *env, union lu_page *lp, struct lu_fid fid; int first = 1; + if (nob < sizeof(*dp)) + return -EINVAL; + memset(area, 0, sizeof (*dp)); area += sizeof (*dp); nob -= sizeof (*dp); @@ -1869,7 +1872,7 @@ static int mdd_dir_page_build(const struct lu_env *env, union lu_page *lp, ent = area; do { int len; - int recsize; + size_t recsize; len = iops->key_size(env, it); diff --git a/lustre/obdclass/dt_object.c b/lustre/obdclass/dt_object.c index 460cbeb..83cf4fb 100644 --- a/lustre/obdclass/dt_object.c +++ b/lustre/obdclass/dt_object.c @@ -666,15 +666,19 @@ static inline const struct dt_index_features *dt_index_feat_select(__u64 seq, * \param arg - is a pointer to the idx_info structure */ static int dt_index_page_build(const struct lu_env *env, union lu_page *lp, - int nob, const struct dt_it_ops *iops, + size_t nob, const struct dt_it_ops *iops, struct dt_it *it, __u32 attr, void *arg) { struct idx_info *ii = (struct idx_info *)arg; struct lu_idxpage *lip = &lp->lp_idx; char *entry; - int rc, size; + size_t size; + int rc; ENTRY; + if (nob < LIP_HDR_SIZE) + return -EINVAL; + /* initialize the header of the new container */ memset(lip, 0, LIP_HDR_SIZE); lip->lip_magic = LIP_MAGIC; @@ -786,7 +790,7 @@ int dt_index_walk(const struct lu_env *env, struct dt_object *obj, { struct dt_it *it; const struct dt_it_ops *iops; - unsigned int pageidx, nob, nlupgs = 0; + size_t pageidx, nob, nlupgs = 0; int rc; ENTRY; @@ -794,7 +798,7 @@ int dt_index_walk(const struct lu_env *env, struct dt_object *obj, LASSERT(obj->do_index_ops != NULL); nob = rdpg->rp_count; - if (nob <= 0) + if (nob == 0) RETURN(-EFAULT); /* Iterate through index and fill containers from @rdpg */ @@ -841,7 +845,7 @@ int dt_index_walk(const struct lu_env *env, struct dt_object *obj, /* fill lu pages */ for (i = 0; i < LU_PAGE_COUNT; i++, lp++, nob -= LU_PAGE_SIZE) { - rc = filler(env, lp, min_t(int, nob, LU_PAGE_SIZE), + rc = filler(env, lp, min_t(size_t, nob, LU_PAGE_SIZE), iops, it, rdpg->rp_attrs, arg); if (rc < 0) break; @@ -859,7 +863,7 @@ out: iops->fini(env, it); if (rc >= 0) - rc = min_t(unsigned int, nlupgs * LU_PAGE_SIZE, rdpg->rp_count); + rc = min_t(size_t, nlupgs * LU_PAGE_SIZE, rdpg->rp_count); RETURN(rc); } -- 1.8.3.1