summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorN Balachandran <nbalacha@redhat.com>2017-08-30 10:01:54 +0530
committerjiffin tony Thottan <jthottan@redhat.com>2017-09-07 06:57:43 +0000
commita862ca969cfd4dc9309e8123e6e90c4e47f9b89b (patch)
treebcc95c0df3054131d8091851d64ef119ae672d13
parente0335c32de133aafd88b888a0c20f4eb88bb9845 (diff)
perf/qr: Use a ref-ed data to extract content
qr_content_extract used dict_get to get the value of the GF_CONTENT_KEY key. dict_get does not ref the data before returning it so QR could be acting on freed memory if another thread deletes the key before then. This patch also fixes a race in dict_get_with_ref. Fix: Use dict_get_with_ref to retrieve the file contents. > BUG: 1484709 > Signed-off-by: N Balachandran <nbalacha@redhat.com> > Reviewed-on: https://review.gluster.org/18115 > Smoke: Gluster Build System <jenkins@build.gluster.org> > Reviewed-by: Amar Tumballi <amarts@redhat.com> > Tested-by: Raghavendra G <rgowdapp@redhat.com> > CentOS-regression: Gluster Build System <jenkins@build.gluster.org> > Reviewed-by: Raghavendra G <rgowdapp@redhat.com> Change-Id: Ib1a7a70bb92eed7e70747ec530e0b3edc53127ec BUG: 1486538 (cherry picked from commit 414d3e92fc56f08e320a3aa65b6b18e65b384551) Signed-off-by: N Balachandran <nbalacha@redhat.com> Reviewed-on: https://review.gluster.org/18145 Reviewed-by: Raghavendra G <rgowdapp@redhat.com> Smoke: Gluster Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: MOHIT AGRAWAL <moagrawa@redhat.com>
-rw-r--r--libglusterfs/src/dict.c13
-rw-r--r--libglusterfs/src/dict.h1
-rw-r--r--xlators/performance/quick-read/src/quick-read.c8
3 files changed, 12 insertions, 10 deletions
diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c
index 22bf3f9..c4f3fb7 100644
--- a/libglusterfs/src/dict.c
+++ b/libglusterfs/src/dict.c
@@ -1433,7 +1433,7 @@ fail:
*/
-static int
+int
dict_get_with_ref (dict_t *this, char *key, data_t **data)
{
data_pair_t * pair = NULL;
@@ -1453,14 +1453,13 @@ dict_get_with_ref (dict_t *this, char *key, data_t **data)
LOCK (&this->lock);
{
pair = dict_lookup_common (this, key, hash);
- }
- UNLOCK (&this->lock);
- if (pair) {
- ret = 0;
- *data = data_ref (pair->value);
+ if (pair) {
+ ret = 0;
+ *data = data_ref (pair->value);
+ }
}
-
+ UNLOCK (&this->lock);
err:
return ret;
}
diff --git a/libglusterfs/src/dict.h b/libglusterfs/src/dict.h
index 93ffa3e..b131363 100644
--- a/libglusterfs/src/dict.h
+++ b/libglusterfs/src/dict.h
@@ -105,6 +105,7 @@ int32_t dict_set (dict_t *this, char *key, data_t *value);
/* function to set a new key/value pair (without checking for duplicate) */
int32_t dict_add (dict_t *this, char *key, data_t *value);
+int dict_get_with_ref (dict_t *this, char *key, data_t **data);
data_t *dict_get (dict_t *this, char *key);
void dict_del (dict_t *this, char *key);
int dict_reset (dict_t *dict);
diff --git a/xlators/performance/quick-read/src/quick-read.c b/xlators/performance/quick-read/src/quick-read.c
index 8edf495..92b2f82 100644
--- a/xlators/performance/quick-read/src/quick-read.c
+++ b/xlators/performance/quick-read/src/quick-read.c
@@ -268,17 +268,19 @@ qr_content_extract (dict_t *xdata)
data_t *data = NULL;
void *content = NULL;
- data = dict_get (xdata, GF_CONTENT_KEY);
+ dict_get_with_ref (xdata, GF_CONTENT_KEY, &data);
if (!data)
return NULL;
content = GF_CALLOC (1, data->len, gf_qr_mt_content_t);
if (!content)
- return NULL;
+ goto out;
memcpy (content, data->data, data->len);
- return content;
+out:
+ data_unref (data);
+ return content;
}