diff options
| author | Amar Tumballi <amar@gluster.com> | 2010-07-28 03:31:10 +0000 | 
|---|---|---|
| committer | Anand V. Avati <avati@dev.gluster.com> | 2010-07-28 03:34:54 -0700 | 
| commit | 927aedbb556ee07250248181f52642eeb6de9e58 (patch) | |
| tree | 034a196708a1c1260951cafeefc42b427bee8479 | |
| parent | 753146c0ff4b1b55892b71b36d6ca97797867aaa (diff) | |
removed last few remaining 'ERR_ABORT's from codebase
Signed-off-by: Amar Tumballi <amar@gluster.com>
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 966 (NULL check for avoiding NULL dereferencing of pointers..)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=966
| -rw-r--r-- | libglusterfs/src/call-stub.c | 8 | ||||
| -rw-r--r-- | libglusterfs/src/common-utils.h | 5 | ||||
| -rw-r--r-- | libglusterfs/src/dict.c | 35 | ||||
| -rw-r--r-- | libglusterfs/src/fd.c | 29 | ||||
| -rw-r--r-- | libglusterfs/src/stack.h | 10 | ||||
| -rw-r--r-- | libglusterfs/src/timer.c | 15 | ||||
| -rw-r--r-- | xlators/Makefile.am | 2 | ||||
| -rw-r--r-- | xlators/encryption/rot-13/src/rot-13.c | 16 | ||||
| -rw-r--r-- | xlators/features/locks/src/common.c | 80 | ||||
| -rw-r--r-- | xlators/mount/fuse/src/fuse-bridge.c | 4 | ||||
| -rw-r--r-- | xlators/protocol/legacy/transport/ib-verbs/src/ib-verbs.c | 16 | 
11 files changed, 152 insertions, 68 deletions
diff --git a/libglusterfs/src/call-stub.c b/libglusterfs/src/call-stub.c index 233a1616250..497637fa9dc 100644 --- a/libglusterfs/src/call-stub.c +++ b/libglusterfs/src/call-stub.c @@ -1738,7 +1738,8 @@ fop_readdirp_cbk_stub (call_frame_t *frame,  	if (op_ret > 0) {  		list_for_each_entry (entry, &entries->list, list) {  			stub_entry = gf_dirent_for_name (entry->d_name); -			ERR_ABORT (stub_entry); +                        if (!stub_entry) +                                goto out;  			stub_entry->d_off = entry->d_off;  			stub_entry->d_ino = entry->d_ino;  			stub_entry->d_stat = entry->d_stat; @@ -1780,11 +1781,12 @@ fop_readdir_cbk_stub (call_frame_t *frame,  	if (op_ret > 0) {  		list_for_each_entry (entry, &entries->list, list) {  			stub_entry = gf_dirent_for_name (entry->d_name); -			ERR_ABORT (stub_entry); +                        if (!stub_entry) +                                goto out;  			stub_entry->d_off = entry->d_off;  			stub_entry->d_ino = entry->d_ino; -			list_add_tail (&stub_entry->list,  +			list_add_tail (&stub_entry->list,  				       &stub->args.readdir_cbk.entries.list);  		}  	} diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index b11e3043f1f..ab230993a5c 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -68,11 +68,6 @@ void trap (void);  #define GF_UNIT_PB_STRING    "PB" -#define ERR_ABORT(ptr)				\ -	if (ptr == NULL)  {			\ -		abort ();			\ -	}                      -  enum _gf_boolean   {  	_gf_false = 0,  diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c index 1f60116238f..4a8945ff136 100644 --- a/libglusterfs/src/dict.c +++ b/libglusterfs/src/dict.c @@ -40,11 +40,12 @@ data_pair_t *  get_new_data_pair ()  {  	data_pair_t *data_pair_ptr = NULL; -   +  	data_pair_ptr = (data_pair_t *) GF_CALLOC (1, sizeof (data_pair_t),                                                     gf_common_mt_data_pair_t); -	ERR_ABORT (data_pair_ptr); -   +        if (!data_pair_ptr) +                gf_log ("dict", GF_LOG_ERROR, "memory alloc failed"); +  	return data_pair_ptr;  } @@ -1064,7 +1065,9 @@ data_to_int64 (data_t *data)  		return -1;  	char *str = alloca (data->len + 1); -	ERR_ABORT (str); +        if (!str) +                return -1; +  	memcpy (str, data->data, data->len);  	str[data->len] = '\0';  	return (int64_t) strtoull (str, NULL, 0); @@ -1077,7 +1080,9 @@ data_to_int32 (data_t *data)  		return -1;  	char *str = alloca (data->len + 1); -	ERR_ABORT (str); +        if (!str) +                return -1; +  	memcpy (str, data->data, data->len);  	str[data->len] = '\0'; @@ -1091,7 +1096,9 @@ data_to_int16 (data_t *data)  		return -1;  	char *str = alloca (data->len + 1); -	ERR_ABORT (str); +        if (!str) +                return -1; +  	memcpy (str, data->data, data->len);  	str[data->len] = '\0'; @@ -1106,7 +1113,9 @@ data_to_int8 (data_t *data)  		return -1;  	char *str = alloca (data->len + 1); -	ERR_ABORT (str); +        if (!str) +                return -1; +  	memcpy (str, data->data, data->len);  	str[data->len] = '\0'; @@ -1120,7 +1129,9 @@ data_to_uint64 (data_t *data)  	if (!data)  		return -1;  	char *str = alloca (data->len + 1); -	ERR_ABORT (str); +        if (!str) +                return -1; +  	memcpy (str, data->data, data->len);  	str[data->len] = '\0'; @@ -1134,7 +1145,9 @@ data_to_uint32 (data_t *data)  		return -1;  	char *str = alloca (data->len + 1); -	ERR_ABORT (str); +        if (!str) +                return -1; +  	memcpy (str, data->data, data->len);  	str[data->len] = '\0'; @@ -1148,7 +1161,9 @@ data_to_uint16 (data_t *data)  		return -1;  	char *str = alloca (data->len + 1); -	ERR_ABORT (str); +        if (!str) +                return -1; +  	memcpy (str, data->data, data->len);  	str[data->len] = '\0'; diff --git a/libglusterfs/src/fd.c b/libglusterfs/src/fd.c index d26854ebdfb..9269e5cf838 100644 --- a/libglusterfs/src/fd.c +++ b/libglusterfs/src/fd.c @@ -87,10 +87,12 @@ gf_fd_fdtable_expand (fdtable_t *fdtable, uint32_t nr)  {  	fdentry_t   *oldfds = NULL;  	uint32_t     oldmax_fds = -1; +        int          ret = -1;  	if (fdtable == NULL || nr < 0) {  		gf_log ("fd", GF_LOG_ERROR, "invalid argument"); -		return EINVAL; +                ret = EINVAL; +                goto out;  	}  	nr /= (1024 / sizeof (fdentry_t)); @@ -102,7 +104,10 @@ gf_fd_fdtable_expand (fdtable_t *fdtable, uint32_t nr)  	fdtable->fdentries = GF_CALLOC (nr, sizeof (fdentry_t),                                          gf_common_mt_fdentry_t); -	ERR_ABORT (fdtable->fdentries); +	if (!fdtable->fdentries) { +                ret = ENOMEM; +                goto out; +        }  	fdtable->max_fds = nr;  	if (oldfds) { @@ -119,7 +124,9 @@ gf_fd_fdtable_expand (fdtable_t *fdtable, uint32_t nr)           */          fdtable->first_free = oldmax_fds;  	GF_FREE (oldfds); -	return 0; +        ret = 0; +out: +	return ret;  } @@ -499,11 +506,17 @@ fd_create (inode_t *inode, pid_t pid)          }          fd = GF_CALLOC (1, sizeof (fd_t), gf_common_mt_fd_t); -        ERR_ABORT (fd); +        if (!fd) +                goto out; -	fd->_ctx = GF_CALLOC (1, (sizeof (struct _fd_ctx) * +        fd->_ctx = GF_CALLOC (1, (sizeof (struct _fd_ctx) *                                    inode->table->xl->graph->xl_count),                                gf_common_mt_fd_ctx); +        if (!fd->_ctx) { +                GF_FREE (fd); +                fd = NULL; +                goto out; +        }          fd->inode = inode_ref (inode);          fd->pid = pid; @@ -512,9 +525,11 @@ fd_create (inode_t *inode, pid_t pid)          LOCK_INIT (&fd->lock);          LOCK (&inode->lock); -        fd = _fd_ref (fd); +        { +                fd = _fd_ref (fd); +        }          UNLOCK (&inode->lock); - +out:          return fd;  } diff --git a/libglusterfs/src/stack.h b/libglusterfs/src/stack.h index 1ce46ccdc89..6015b8158b0 100644 --- a/libglusterfs/src/stack.h +++ b/libglusterfs/src/stack.h @@ -184,7 +184,10 @@ STACK_DESTROY (call_stack_t *stack)  		                                                        \                  _new = GF_CALLOC (1, sizeof (call_frame_t),             \                                  gf_common_mt_call_frame_t);	        \ -		ERR_ABORT (_new);					\ +                if (!_new) {                                            \ +                        gf_log ("stack", GF_LOG_ERROR, "alloc failed"); \ +                        break;                                          \ +                }                                                       \  		typeof(fn##_cbk) tmp_cbk = rfn;				\  		_new->root = frame->root;				\  		_new->next = frame->root->frames.next;			\ @@ -219,7 +222,10 @@ STACK_DESTROY (call_stack_t *stack)                                                                          \                  _new = GF_CALLOC (1, sizeof (call_frame_t),             \                                  gf_common_mt_call_frame_t);	        \ -		ERR_ABORT (_new);					\ +                if (!_new) {                                            \ +                        gf_log ("stack", GF_LOG_ERROR, "alloc failed"); \ +                        break;                                          \ +                }                                                       \  		typeof(fn##_cbk) tmp_cbk = rfn;				\  		_new->root = frame->root;				\  		_new->next = frame->root->frames.next;			\ diff --git a/libglusterfs/src/timer.c b/libglusterfs/src/timer.c index 7ff18f94e35..3e39231e0b7 100644 --- a/libglusterfs/src/timer.c +++ b/libglusterfs/src/timer.c @@ -201,18 +201,19 @@ gf_timer_proc (void *ctx)  gf_timer_registry_t *  gf_timer_registry_init (glusterfs_ctx_t *ctx)  { -        if (ctx == NULL) -        { +        if (ctx == NULL) {                  gf_log ("timer", GF_LOG_ERROR, "invalid argument");                  return NULL;          } -   +          if (!ctx->timer) {                  gf_timer_registry_t *reg = NULL; -                ctx->timer = reg = GF_CALLOC (1, sizeof (*reg), -                                           gf_common_mt_gf_timer_registry_t); -                ERR_ABORT (reg); +                reg = GF_CALLOC (1, sizeof (*reg), +                                 gf_common_mt_gf_timer_registry_t); +                if (!reg) +                        goto out; +                  pthread_mutex_init (®->lock, NULL);                  reg->active.next = ®->active;                  reg->active.prev = ®->active; @@ -220,6 +221,8 @@ gf_timer_registry_init (glusterfs_ctx_t *ctx)                  reg->stale.prev = ®->stale;                  pthread_create (®->th, NULL, gf_timer_proc, ctx); +                ctx->timer = reg;          } +out:          return ctx->timer;  } diff --git a/xlators/Makefile.am b/xlators/Makefile.am index 495a6829114..4c94f5e44c1 100644 --- a/xlators/Makefile.am +++ b/xlators/Makefile.am @@ -1,3 +1,3 @@  SUBDIRS = cluster storage protocol performance debug features encryption mount nfs mgmt -CLEANFILES =  +CLEANFILES = diff --git a/xlators/encryption/rot-13/src/rot-13.c b/xlators/encryption/rot-13/src/rot-13.c index a334b669df0..9d5dab03307 100644 --- a/xlators/encryption/rot-13/src/rot-13.c +++ b/xlators/encryption/rot-13/src/rot-13.c @@ -145,9 +145,11 @@ init (xlator_t *this)  		gf_log (this->name, GF_LOG_WARNING,  			"dangling volume. check volfile ");  	} -   -	priv = CALLOC (sizeof (rot_13_private_t), 1); -	ERR_ABORT (priv); + +	priv = GF_CALLOC (sizeof (rot_13_private_t), 1, 0); +        if (!priv) +                return -1; +  	priv->decrypt_read = 1;  	priv->encrypt_write = 1; @@ -174,13 +176,13 @@ init (xlator_t *this)  	return 0;  } -void  +void  fini (xlator_t *this)  {  	rot_13_private_t *priv = this->private; -	 -	FREE (priv); -	 + +	GF_FREE (priv); +  	return;  } diff --git a/xlators/features/locks/src/common.c b/xlators/features/locks/src/common.c index 2ba8df002cf..b34cd97813a 100644 --- a/xlators/features/locks/src/common.c +++ b/xlators/features/locks/src/common.c @@ -590,70 +590,106 @@ struct _values {  static struct _values  subtract_locks (posix_lock_t *big, posix_lock_t *small)  { +  	struct _values v = { .locks = {0, 0, 0} }; -   -	if ((big->fl_start == small->fl_start) &&  -	    (big->fl_end   == small->fl_end)) {   + +	if ((big->fl_start == small->fl_start) && +	    (big->fl_end   == small->fl_end)) {  		/* both edges coincide with big */  		v.locks[0] = GF_CALLOC (1, sizeof (posix_lock_t),                                          gf_locks_mt_posix_lock_t); -		ERR_ABORT (v.locks[0]); +                if (!v.locks[0]) +                        goto out;  		memcpy (v.locks[0], big, sizeof (posix_lock_t));  		v.locks[0]->fl_type = small->fl_type; +                goto done;  	} -	else if ((small->fl_start > big->fl_start) && -		 (small->fl_end   < big->fl_end)) { + +	if ((small->fl_start > big->fl_start) && +            (small->fl_end   < big->fl_end)) {  		/* both edges lie inside big */  		v.locks[0] = GF_CALLOC (1, sizeof (posix_lock_t),                                          gf_locks_mt_posix_lock_t); -		ERR_ABORT (v.locks[0]); +                if (!v.locks[0]) +                        goto out; +  		v.locks[1] = GF_CALLOC (1, sizeof (posix_lock_t),                                          gf_locks_mt_posix_lock_t); -		ERR_ABORT (v.locks[1]); +                if (!v.locks[1]) +                        goto out; +  		v.locks[2] = GF_CALLOC (1, sizeof (posix_lock_t),                                          gf_locks_mt_posix_lock_t); -		ERR_ABORT (v.locks[2]); +                if (!v.locks[1]) +                        goto out;  		memcpy (v.locks[0], big, sizeof (posix_lock_t));  		v.locks[0]->fl_end = small->fl_start - 1;  		memcpy (v.locks[1], small, sizeof (posix_lock_t)); +  		memcpy (v.locks[2], big, sizeof (posix_lock_t));  		v.locks[2]->fl_start = small->fl_end + 1; +                goto done; +  	} +  	/* one edge coincides with big */ -	else if (small->fl_start == big->fl_start) { +        if (small->fl_start == big->fl_start) {  		v.locks[0] = GF_CALLOC (1, sizeof (posix_lock_t),                                          gf_locks_mt_posix_lock_t); -		ERR_ABORT (v.locks[0]); +                if (!v.locks[0]) +                        goto out; +  		v.locks[1] = GF_CALLOC (1, sizeof (posix_lock_t),                                          gf_locks_mt_posix_lock_t); -		ERR_ABORT (v.locks[1]); -     +                if (!v.locks[1]) +                        goto out; +  		memcpy (v.locks[0], big, sizeof (posix_lock_t));  		v.locks[0]->fl_start = small->fl_end + 1; -     +  		memcpy (v.locks[1], small, sizeof (posix_lock_t)); +                goto done;  	} -	else if (small->fl_end   == big->fl_end) { + +	if (small->fl_end  == big->fl_end) {  		v.locks[0] = GF_CALLOC (1, sizeof (posix_lock_t),                                          gf_locks_mt_posix_lock_t); -		ERR_ABORT (v.locks[0]); +                if (!v.locks[0]) +                        goto out; +  		v.locks[1] = GF_CALLOC (1, sizeof (posix_lock_t),                                          gf_locks_mt_posix_lock_t); -		ERR_ABORT (v.locks[1]); +                if (!v.locks[1]) +                        goto out;  		memcpy (v.locks[0], big, sizeof (posix_lock_t));  		v.locks[0]->fl_end = small->fl_start - 1; -     +  		memcpy (v.locks[1], small, sizeof (posix_lock_t)); +                goto done;  	} -        else { -                gf_log ("posix-locks", GF_LOG_ERROR, -                        "Unexpected case in subtract_locks. Please send " -                        "a bug report to gluster-devel@nongnu.org"); + +        gf_log ("posix-locks", GF_LOG_ERROR, +                "Unexpected case in subtract_locks. Please send " +                "a bug report to gluster-devel@nongnu.org"); + +out: +        if (v.locks[0]) { +                GF_FREE (v.locks[0]); +                v.locks[0] = NULL; +        } +        if (v.locks[1]) { +                GF_FREE (v.locks[1]); +                v.locks[1] = NULL; +        } +        if (v.locks[2]) { +                GF_FREE (v.locks[2]); +                v.locks[2] = NULL;          } +done:          return v;  } diff --git a/xlators/mount/fuse/src/fuse-bridge.c b/xlators/mount/fuse/src/fuse-bridge.c index e5df3648033..b1de4692a10 100644 --- a/xlators/mount/fuse/src/fuse-bridge.c +++ b/xlators/mount/fuse/src/fuse-bridge.c @@ -2594,7 +2594,8 @@ fuse_xattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,                                  trav = trav->next;                          } /* while(trav) */                          value = alloca (len + 1); -                        ERR_ABORT (value); +                        if (!value) +                                goto out;                          len = 0;                          trav = dict->members_list;                          while (trav) { @@ -2633,6 +2634,7 @@ fuse_xattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,                  send_fuse_err (this, finh, op_errno);          } /* if(op_ret>=0)...else */ +out:          if (need_to_free_dict)                  dict_unref (dict); diff --git a/xlators/protocol/legacy/transport/ib-verbs/src/ib-verbs.c b/xlators/protocol/legacy/transport/ib-verbs/src/ib-verbs.c index 85228bf4e58..0db996405e8 100644 --- a/xlators/protocol/legacy/transport/ib-verbs/src/ib-verbs.c +++ b/xlators/protocol/legacy/transport/ib-verbs/src/ib-verbs.c @@ -731,7 +731,8 @@ ib_verbs_register_peer (ib_verbs_device_t *device,                  return;          }          ent = (struct _qpent *) GF_CALLOC (1, sizeof (*ent), gf_ibv_mt_qpent); -        ERR_ABORT (ent); +        if (!ent) +                return;          /* TODO: ref reg->peer */          ent->peer = peer;          ent->next = &qpreg->ents[hash]; @@ -1522,7 +1523,8 @@ ib_verbs_get_device (transport_t *this,                  trav = GF_CALLOC (1, sizeof (*trav),                                     gf_ibv_mt_ib_verbs_device_t); -                ERR_ABORT (trav); +                if (!trav) +                        return NULL;                  priv->device = trav;                  trav->context = ibctx; @@ -2357,10 +2359,16 @@ ib_verbs_server_event_handler (int fd, int idx, void *data,          this = GF_CALLOC (1, sizeof (transport_t),                            gf_ibv_mt_transport_t); -        ERR_ABORT (this); +        if (!this) +                return 0; +          priv = GF_CALLOC (1, sizeof (ib_verbs_private_t),                            gf_ibv_mt_ib_verbs_private_t); -        ERR_ABORT (priv); +        if (!priv) { +                GF_FREE (this); +                return 0; +        } +          this->private = priv;          /* Copy all the ib_verbs related values in priv, from trans_priv              as other than QP, all the values remain same */  | 
