From 3fe535afa61fa06c066e511c3c6e269902924296 Mon Sep 17 00:00:00 2001 From: Poornima G Date: Thu, 3 Aug 2017 17:43:22 +0530 Subject: gfapi: Duplicate the buffer sent in setxattr calls Issue: The caller of glfs_setxattr sends a buffer to set as the value. We create a dict in which the pointer to the value is set. Underlying layers like md-cache take a ref on this dict to store the value for a longer time. But the moment setxattr is complete, the caller of glfs_setxattr can free the value memory. Solution: memcpy the setxattr value to the gluster buffer. > Reviewed-on: https://review.gluster.org/17967 > Reviewed-by: soumya k > Smoke: Gluster Build System > CentOS-regression: Gluster Build System > Reviewed-by: Jeff Darcy > (cherry picked from commit e11296f8e52b7e3b13d21b41d4fa34baea878edf) Change-Id: I58753fe702e8b7d0f6c4f058714c65d0ad5d7a0a BUG: 1479656 Signed-off-by: Poornima G Reviewed-on: https://review.gluster.org/18002 Smoke: Gluster Build System CentOS-regression: Gluster Build System Reviewed-by: Shyamsundar Ranganathan --- libglusterfs/src/dict.c | 10 ++++++++-- libglusterfs/src/dict.h | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'libglusterfs/src') diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c index 839b42685e8..1aa873e77bd 100644 --- a/libglusterfs/src/dict.c +++ b/libglusterfs/src/dict.c @@ -3018,7 +3018,8 @@ dict_dump_to_statedump (dict_t *dict, char *dict_name, char *domain) } dict_t * -dict_for_key_value (const char *name, const char *value, size_t size) +dict_for_key_value (const char *name, const char *value, size_t size, + gf_boolean_t is_static) { dict_t *xattr = NULL; int ret = 0; @@ -3027,7 +3028,12 @@ dict_for_key_value (const char *name, const char *value, size_t size) if (!xattr) return NULL; - ret = dict_set_static_bin (xattr, (char *)name, (void *)value, size); + if (is_static) + ret = dict_set_static_bin (xattr, (char *)name, (void *)value, + size); + else + ret = dict_set_bin (xattr, (char *)name, (void *)value, size); + if (ret) { dict_destroy (xattr); xattr = NULL; diff --git a/libglusterfs/src/dict.h b/libglusterfs/src/dict.h index bef58e102cc..72198d43d50 100644 --- a/libglusterfs/src/dict.h +++ b/libglusterfs/src/dict.h @@ -254,7 +254,8 @@ gf_boolean_t dict_match_everything (dict_t *d, char *k, data_t *v, void *data); dict_t * -dict_for_key_value (const char *name, const char *value, size_t size); +dict_for_key_value (const char *name, const char *value, size_t size, + gf_boolean_t is_static); gf_boolean_t are_dicts_equal (dict_t *one, dict_t *two, -- cgit