summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/dict.c
diff options
context:
space:
mode:
Diffstat (limited to 'libglusterfs/src/dict.c')
-rw-r--r--libglusterfs/src/dict.c130
1 files changed, 103 insertions, 27 deletions
diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c
index e2fce75..5f81c48 100644
--- a/libglusterfs/src/dict.c
+++ b/libglusterfs/src/dict.c
@@ -545,9 +545,9 @@ dict_addn(dict_t *this, char *key, const int keylen, data_t *value)
data_t *
dict_get(dict_t *this, char *key)
{
- if (!key) {
+ if (!this || !key) {
gf_msg_callingfn("dict", GF_LOG_DEBUG, EINVAL, LG_MSG_INVALID_ARG,
- "!key");
+ "!this || key=%s", (key) ? key : "()");
return NULL;
}
@@ -603,9 +603,9 @@ dict_key_count(dict_t *this)
void
dict_del(dict_t *this, char *key)
{
- if (!key) {
+ if (!this || !key) {
gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG,
- "!key");
+ "!this || key=%s", key);
return;
}
@@ -620,7 +620,7 @@ dict_deln(dict_t *this, char *key, const int keylen)
if (!this || !key) {
gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG,
- "!this || key=%s", (key) ? key : "()");
+ "!this || key=%s", key);
return;
}
@@ -1267,6 +1267,12 @@ dict_null_foreach_fn(dict_t *d, char *k, data_t *v, void *tmp)
int
dict_remove_foreach_fn(dict_t *d, char *k, data_t *v, void *_tmp)
{
+ if (!d || !k) {
+ gf_msg("glusterfs", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ENTRY,
+ "%s is NULL", d ? "key" : "dictionary");
+ return -1;
+ }
+
dict_del(d, k);
return 0;
}
@@ -1458,9 +1464,9 @@ fail:
int
dict_get_with_ref(dict_t *this, char *key, data_t **data)
{
- if (!key) {
+ if (!this || !key || !data) {
gf_msg_callingfn("dict", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG,
- "!key");
+ "dict OR key (%s) is NULL", key);
return -EINVAL;
}
@@ -1498,15 +1504,36 @@ err:
}
static int
+data_to_ptr_common(data_t *data, void **val)
+{
+ int ret = 0;
+
+ if (!data) {
+ ret = -EINVAL;
+ goto err;
+ }
+
+ *val = data->data;
+err:
+ return ret;
+}
+
+static int
data_to_int8_ptr(data_t *data, int8_t *val)
{
int ret = 0;
+ if (!data || !val) {
+ ret = -EINVAL;
+ goto err;
+ }
+
errno = 0;
*val = strtol(data->data, NULL, 0);
if (errno != 0)
ret = -errno;
+err:
return ret;
}
@@ -1515,11 +1542,17 @@ data_to_int16_ptr(data_t *data, int16_t *val)
{
int ret = 0;
+ if (!data || !val) {
+ ret = -EINVAL;
+ goto err;
+ }
+
errno = 0;
*val = strtol(data->data, NULL, 0);
if (errno != 0)
ret = -errno;
+err:
return ret;
}
@@ -1528,11 +1561,17 @@ data_to_int32_ptr(data_t *data, int32_t *val)
{
int ret = 0;
+ if (!data || !val) {
+ ret = -EINVAL;
+ goto err;
+ }
+
errno = 0;
*val = strtol(data->data, NULL, 0);
if (errno != 0)
ret = -errno;
+err:
return ret;
}
@@ -1541,11 +1580,17 @@ data_to_int64_ptr(data_t *data, int64_t *val)
{
int ret = 0;
+ if (!data || !val) {
+ ret = -EINVAL;
+ goto err;
+ }
+
errno = 0;
*val = strtoll(data->data, NULL, 0);
if (errno != 0)
ret = -errno;
+err:
return ret;
}
@@ -1554,11 +1599,17 @@ data_to_uint16_ptr(data_t *data, uint16_t *val)
{
int ret = 0;
+ if (!data || !val) {
+ ret = -EINVAL;
+ goto err;
+ }
+
errno = 0;
*val = strtoul(data->data, NULL, 0);
if (errno != 0)
ret = -errno;
+err:
return ret;
}
@@ -1567,11 +1618,17 @@ data_to_uint32_ptr(data_t *data, uint32_t *val)
{
int ret = 0;
+ if (!data || !val) {
+ ret = -EINVAL;
+ goto err;
+ }
+
errno = 0;
*val = strtoul(data->data, NULL, 0);
if (errno != 0)
ret = -errno;
+err:
return ret;
}
@@ -1580,11 +1637,17 @@ data_to_uint64_ptr(data_t *data, uint64_t *val)
{
int ret = 0;
+ if (!data || !val) {
+ ret = -EINVAL;
+ goto err;
+ }
+
errno = 0;
*val = strtoull(data->data, NULL, 0);
if (errno != 0)
ret = -errno;
+err:
return ret;
}
@@ -1613,7 +1676,7 @@ dict_get_int8(dict_t *this, char *key, int8_t *val)
data_t *data = NULL;
int ret = 0;
- if (!val) {
+ if (!this || !key || !val) {
ret = -EINVAL;
goto err;
}
@@ -1659,7 +1722,7 @@ dict_get_int16(dict_t *this, char *key, int16_t *val)
data_t *data = NULL;
int ret = 0;
- if (!val) {
+ if (!this || !key || !val) {
ret = -EINVAL;
goto err;
}
@@ -1705,7 +1768,7 @@ dict_get_int32n(dict_t *this, char *key, const int keylen, int32_t *val)
data_t *data = NULL;
int ret = 0;
- if (!val) {
+ if (!this || !key || !val) {
ret = -EINVAL;
goto err;
}
@@ -1731,7 +1794,7 @@ dict_get_int32(dict_t *this, char *key, int32_t *val)
data_t *data = NULL;
int ret = 0;
- if (!val) {
+ if (!this || !key || !val) {
ret = -EINVAL;
goto err;
}
@@ -1796,7 +1859,7 @@ dict_get_int64(dict_t *this, char *key, int64_t *val)
data_t *data = NULL;
int ret = 0;
- if (!val) {
+ if (!this || !key || !val) {
ret = -EINVAL;
goto err;
}
@@ -1841,7 +1904,7 @@ dict_get_uint16(dict_t *this, char *key, uint16_t *val)
data_t *data = NULL;
int ret = 0;
- if (!val) {
+ if (!this || !key || !val) {
ret = -EINVAL;
goto err;
}
@@ -1886,7 +1949,7 @@ dict_get_uint32(dict_t *this, char *key, uint32_t *val)
data_t *data = NULL;
int ret = 0;
- if (!val) {
+ if (!this || !key || !val) {
ret = -EINVAL;
goto err;
}
@@ -1931,7 +1994,7 @@ dict_get_uint64(dict_t *this, char *key, uint64_t *val)
data_t *data = NULL;
int ret = 0;
- if (!val) {
+ if (!this || !key || !val) {
ret = -EINVAL;
goto err;
}
@@ -2156,7 +2219,7 @@ dict_get_double(dict_t *this, char *key, double *val)
data_t *data = NULL;
int ret = 0;
- if (!val) {
+ if (!this || !key || !val) {
ret = -EINVAL;
goto err;
}
@@ -2239,7 +2302,7 @@ dict_get_ptr(dict_t *this, char *key, void **ptr)
data_t *data = NULL;
int ret = 0;
- if (!ptr) {
+ if (!this || !key || !ptr) {
ret = -EINVAL;
goto err;
}
@@ -2251,7 +2314,10 @@ dict_get_ptr(dict_t *this, char *key, void **ptr)
VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_PTR, key, -EINVAL);
- *ptr = data->data;
+ ret = data_to_ptr_common(data, ptr);
+ if (ret != 0) {
+ goto err;
+ }
err:
if (data)
@@ -2266,7 +2332,7 @@ dict_get_ptr_and_len(dict_t *this, char *key, void **ptr, int *len)
data_t *data = NULL;
int ret = 0;
- if (!ptr) {
+ if (!this || !key || !ptr) {
ret = -EINVAL;
goto err;
}
@@ -2279,7 +2345,11 @@ dict_get_ptr_and_len(dict_t *this, char *key, void **ptr, int *len)
VALIDATE_DATA_AND_LOG(data, GF_DATA_TYPE_PTR, key, -EINVAL);
*len = data->len;
- *ptr = data->data;
+
+ ret = data_to_ptr_common(data, ptr);
+ if (ret != 0) {
+ goto err;
+ }
err:
if (data)
@@ -2295,7 +2365,7 @@ dict_get_strn(dict_t *this, char *key, const int keylen, char **str)
data_t *data = NULL;
int ret = -EINVAL;
- if (!str) {
+ if (!this || !key || !str) {
goto err;
}
ret = dict_get_with_refn(this, key, keylen, &data);
@@ -2320,7 +2390,7 @@ dict_get_str(dict_t *this, char *key, char **str)
data_t *data = NULL;
int ret = -EINVAL;
- if (!str) {
+ if (!this || !key || !str) {
goto err;
}
ret = dict_get_with_ref(this, key, &data);
@@ -2494,7 +2564,7 @@ dict_get_bin(dict_t *this, char *key, void **bin)
data_t *data = NULL;
int ret = -EINVAL;
- if (!bin) {
+ if (!this || !key || !bin) {
goto err;
}
@@ -2530,7 +2600,7 @@ dict_set_bin_common(dict_t *this, char *key, void *ptr, size_t size,
data_t *data = NULL;
int ret = 0;
- if (size > DICT_KEY_VALUE_MAX_SIZE) {
+ if (!ptr || (size > DICT_KEY_VALUE_MAX_SIZE)) {
ret = -EINVAL;
goto err;
}
@@ -2597,7 +2667,7 @@ dict_get_gfuuid(dict_t *this, char *key, uuid_t *gfid)
data_t *data = NULL;
int ret = -EINVAL;
- if (!gfid) {
+ if (!this || !key || !gfid) {
goto err;
}
ret = dict_get_with_ref(this, key, &data);
@@ -2630,7 +2700,7 @@ dict_get_mdata(dict_t *this, char *key, struct mdata_iatt *mdata)
data_t *data = NULL;
int ret = -EINVAL;
- if (!mdata) {
+ if (!this || !key || !mdata) {
goto err;
}
ret = dict_get_with_ref(this, key, &data);
@@ -2668,7 +2738,7 @@ dict_get_iatt(dict_t *this, char *key, struct iatt *iatt)
data_t *data = NULL;
int ret = -EINVAL;
- if (!iatt) {
+ if (!this || !key || !iatt) {
goto err;
}
ret = dict_get_with_ref(this, key, &data);
@@ -2877,6 +2947,12 @@ dict_serialize_lk(dict_t *this, char *buf)
int32_t keylen = 0;
int32_t netword = 0;
+ if (!buf) {
+ gf_msg("dict", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG,
+ "buf is null!");
+ goto out;
+ }
+
if (count < 0) {
gf_msg("dict", GF_LOG_ERROR, 0, LG_MSG_COUNT_LESS_THAN_ZERO,
"count (%d) < 0!", count);