diff options
| author | Yaniv Kaul <ykaul@redhat.com> | 2018-08-27 23:45:15 +0300 | 
|---|---|---|
| committer | Amar Tumballi <amarts@redhat.com> | 2018-08-31 01:26:31 +0000 | 
| commit | 3ff3b5823bed9d43d2966c1a3b45f26631d15897 (patch) | |
| tree | 843a9cefc32a8c91f262abad29e160b8419b2ec5 | |
| parent | d3b1456c52f7dc4f21cdae2855092fda6b96af4a (diff) | |
libglusterfs/src/dict.c: fix to handle key=NULL.
We don't want to strlen NULL strings.
Compile-tested only!
updates: bz#1193929
Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
Change-Id: Id795998693ba410dbd80df962d48956a9e4164c4
| -rw-r--r-- | libglusterfs/src/dict.c | 41 | 
1 files changed, 31 insertions, 10 deletions
diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c index b69f0e79a47..8849baf290a 100644 --- a/libglusterfs/src/dict.c +++ b/libglusterfs/src/dict.c @@ -491,8 +491,10 @@ dict_set (dict_t *this,            char *key,            data_t *value)  { -        const int keylen = strlen(key); -        return dict_setn(this, key, keylen, value); +        if (key) +                return dict_setn (this, key, strlen (key), value); +        else +                return dict_setn (this, NULL, 0, value);  }  int32_t @@ -528,8 +530,10 @@ dict_setn (dict_t *this,  int32_t  dict_add (dict_t *this, char *key, data_t *value)  { -        const int keylen = strlen (key); -        return dict_addn(this, key, keylen, value); +        if (key) +                return dict_addn(this, key, strlen (key), value); +        else +                return dict_addn(this, NULL, 0, value);  }  int32_t @@ -562,8 +566,14 @@ dict_addn (dict_t *this, char *key, const int keylen, data_t *value)  data_t *  dict_get (dict_t *this, char *key)  { -        const int keylen = strlen(key); -        return dict_getn(this, key, keylen); +        if (!this || !key) { +                gf_msg_callingfn ("dict", GF_LOG_INFO, EINVAL, +                                  LG_MSG_INVALID_ARG, +                                  "!this || key=%s", (key) ? key : "()"); +                return NULL; +        } + +        return dict_getn(this, key, strlen (key));  }  data_t * @@ -616,8 +626,13 @@ dict_key_count (dict_t *this)  void  dict_del (dict_t *this, char *key)  { -        const int keylen = strlen(key); -        return dict_deln(this, key, keylen); +        if (!this || !key) { +                gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, +                                  LG_MSG_INVALID_ARG, "!this || key=%s", key); +                return; +        } + +        return dict_deln(this, key, strlen (key));  }  void @@ -1545,8 +1560,14 @@ fail:  int  dict_get_with_ref (dict_t *this, char *key, data_t **data)  { -        const int keylen = strlen(key); -        return dict_get_with_refn(this, key, keylen, data); +        if (!this || !key || !data) { +                gf_msg_callingfn ("dict", GF_LOG_WARNING, EINVAL, +                                  LG_MSG_INVALID_ARG, +                                  "dict OR key (%s) is NULL", key); +                return -EINVAL; +        } + +        return dict_get_with_refn(this, key, strlen (key), data);  }  int  | 
