diff options
author | Mohit Agrawal <moagrawa@redhat.com> | 2017-11-10 14:47:31 +0530 |
---|---|---|
committer | Jeff Darcy <jeff@pl.atyp.us> | 2017-11-15 14:37:31 +0000 |
commit | 959f5267fa8592d75dda9a3892378c48c55eee35 (patch) | |
tree | 455ff50de61900d28d781746adb5076fe17a512b /libglusterfs | |
parent | c46618973a22875bca4ac8835cc71bb8f3aeaa65 (diff) |
dict: Fix several coverity issues in dict
This patch fixes issues 230,592,593,110,63 from [1]
[1] https://download.gluster.org/pub/gluster/glusterfs/static-analysis/master/glusterfs-coverity/2017-10-30-9aa574a5/html/
Note: Resolve FORWARD_NULL coverity issue in glusterfs_ctx_new is
also fixed with this patch.
BUG: 789278
Change-Id: Ic4199a144a14cc9ead7366fb1c9699197141bc86
Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
Diffstat (limited to 'libglusterfs')
-rw-r--r-- | libglusterfs/src/ctx.c | 1 | ||||
-rw-r--r-- | libglusterfs/src/dict.c | 44 | ||||
-rw-r--r-- | libglusterfs/src/dict.h | 2 |
3 files changed, 37 insertions, 10 deletions
diff --git a/libglusterfs/src/ctx.c b/libglusterfs/src/ctx.c index 90480d09774..afd12cd22f8 100644 --- a/libglusterfs/src/ctx.c +++ b/libglusterfs/src/ctx.c @@ -48,6 +48,7 @@ glusterfs_ctx_new () if (ret) { free (ctx); ctx = NULL; + goto out; } GF_ATOMIC_INIT (ctx->stats.max_dict_pairs, 0); diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c index 243c92985a8..a47c8529709 100644 --- a/libglusterfs/src/dict.c +++ b/libglusterfs/src/dict.c @@ -2337,7 +2337,7 @@ dict_set_bin_common (dict_t *this, char *key, void *ptr, size_t size, data_t * data = NULL; int ret = 0; - if (!ptr || (size > ULONG_MAX)) { + if (!ptr || (size > DICT_KEY_VALUE_MAX_SIZE)) { ret = -EINVAL; goto err; } @@ -2845,7 +2845,9 @@ dict_unserialize (char *orig_buf, int32_t size, dict_t **fill) value->is_static = 0; buf += vallen; - dict_add (*fill, key, value); + ret = dict_add (*fill, key, value); + if (ret < 0) + goto out; } ret = 0; @@ -3032,23 +3034,34 @@ void dict_dump_to_log (dict_t *dict) { int ret = -1; - char dump[64*1024] = {0,}; + char *dump = NULL; + int dump_size = 64*1024; char *format = "(%s:%s)"; if (!dict) { gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, "dict is NULL"); - return; + goto out; + } + + dump = GF_CALLOC (1, dump_size, gf_common_mt_char); + if (!dump) { + gf_msg_callingfn ("dict", GF_LOG_WARNING, ENOMEM, + LG_MSG_NO_MEMORY, "dump buffer is NULL"); + goto out; } - ret = dict_dump_to_str (dict, dump, sizeof(dump), format); + ret = dict_dump_to_str (dict, dump, dump_size, format); if (ret) { gf_msg ("dict", GF_LOG_WARNING, 0, LG_MSG_FAILED_TO_LOG_DICT, "Failed to log dictionary"); - return; + goto out; } gf_msg_callingfn ("dict", GF_LOG_INFO, 0, LG_MSG_DICT_ERROR, "dict=%p (%s)", dict, dump); +out: + GF_FREE (dump); + return; } @@ -3057,25 +3070,36 @@ void dict_dump_to_statedump (dict_t *dict, char *dict_name, char *domain) { int ret = -1; - char dump[64*1024] = {0,}; + char *dump = NULL; + int dump_size = 64*1024; char key[4096] = {0,}; char *format = "\n\t%s:%s"; if (!dict) { gf_msg_callingfn (domain, GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG, "dict is NULL"); - return; + goto out; + } + + dump = GF_CALLOC (1, dump_size, gf_common_mt_char); + if (!dump) { + gf_msg_callingfn (domain, GF_LOG_WARNING, ENOMEM, + LG_MSG_NO_MEMORY, "dump buffer is NULL"); + goto out; } - ret = dict_dump_to_str (dict, dump, sizeof(dump), format); + ret = dict_dump_to_str (dict, dump, dump_size, format); if (ret) { gf_msg (domain, GF_LOG_WARNING, 0, LG_MSG_FAILED_TO_LOG_DICT, "Failed to log dictionary %s", dict_name); - return; + goto out; } gf_proc_dump_build_key (key, domain, "%s", dict_name); gf_proc_dump_write (key, "%s", dump); +out: + GF_FREE (dump); + return; } diff --git a/libglusterfs/src/dict.h b/libglusterfs/src/dict.h index b1313636092..713da61d4ce 100644 --- a/libglusterfs/src/dict.h +++ b/libglusterfs/src/dict.h @@ -60,6 +60,8 @@ typedef struct _data_pair data_pair_t; \ } while (0) +#define DICT_KEY_VALUE_MAX_SIZE 1048576 + struct _data { unsigned char is_static:1; unsigned char is_const:1; |