From 2f15ffd6b5beef9abd501c594bc3cb38c2683f77 Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Fri, 2 Jul 2010 04:55:28 +0000 Subject: NULL dereference fixes in code base after running with 'clang' * 212 logical (NULL deref/divide by zero) errors reduced to 28 (27 of them in contrib/ and lex part of codebase, 1 is invalid) * 11 API errors reduced to 0 Signed-off-by: Amar Tumballi Signed-off-by: Anand V. Avati BUG: 966 (NULL check for avoiding NULL dereferencing of pointers..) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=966 --- xlators/cluster/stripe/src/stripe.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'xlators/cluster/stripe/src/stripe.c') diff --git a/xlators/cluster/stripe/src/stripe.c b/xlators/cluster/stripe/src/stripe.c index 99346fac23f..4826d80a8f2 100644 --- a/xlators/cluster/stripe/src/stripe.c +++ b/xlators/cluster/stripe/src/stripe.c @@ -3284,7 +3284,6 @@ stripe_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, call_frame_t *rframe = NULL; stripe_local_t *rlocal = NULL; xlator_list_t *trav = NULL; - stripe_private_t *priv = NULL; stripe_fd_ctx_t *fctx = NULL; VALIDATE_OR_GOTO (frame, err); @@ -3293,7 +3292,6 @@ stripe_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, VALIDATE_OR_GOTO (fd->inode, err); trav = this->children; - priv = this->private; fd_ctx_get (fd, this, &tmp_fctx); if (!tmp_fctx) { @@ -3303,6 +3301,11 @@ stripe_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, fctx = (stripe_fd_ctx_t *)(long)tmp_fctx; stripe_size = fctx->stripe_size; + if (!stripe_size) { + gf_log (this->name, GF_LOG_DEBUG, + "Wrong stripe size for the file"); + goto err; + } /* The file is stripe across the child nodes. Send the read request * to the child nodes appropriately after checking which region of * the file is in which child node. Always '0-' part of @@ -3310,7 +3313,7 @@ stripe_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, */ rounded_start = floor (offset, stripe_size); rounded_end = roof (offset+size, stripe_size); - num_stripe = rounded_end/stripe_size - rounded_start/stripe_size; + num_stripe = (rounded_end- rounded_start)/stripe_size; local = GF_CALLOC (1, sizeof (stripe_local_t), gf_stripe_mt_stripe_local_t); @@ -3361,7 +3364,7 @@ stripe_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, return 0; err: - if (local->fd) + if (local && local->fd) fd_unref (local->fd); STACK_UNWIND_STRICT (readv, frame, -1, op_errno, NULL, 0, NULL, NULL); -- cgit