summaryrefslogtreecommitdiffstats
path: root/xlators/performance/nl-cache/src
diff options
context:
space:
mode:
authorXavi Hernandez <xhernandez@redhat.com>2019-12-20 14:14:32 +0100
committerAmar Tumballi <amarts@gmail.com>2020-01-10 00:58:19 +0000
commit00c090b093c147a95bfb8fce93f08303993e1995 (patch)
tree537f9d4104bc1290dc2419c4ce9341bc6ee31dc8 /xlators/performance/nl-cache/src
parent1166df1920dd9b2bd5fce53ab49d27117db40238 (diff)
multiple: fix bad type cast
When using inode_ctx_get() or inode_ctx_set(), a 'uint64_t *' is expected. In many cases, the value to retrieve or store is a pointer, which will be of smaller size in some architectures (for example 32-bits). In this case, directly passing the address of the pointer casted to an 'uint64_t *' is wrong and can cause memory corruption. Change-Id: Iae616da9dda528df6743fa2f65ae5cff5ad23258 Signed-off-by: Xavi Hernandez <xhernandez@redhat.com> Fixes: bz#1785611
Diffstat (limited to 'xlators/performance/nl-cache/src')
-rw-r--r--xlators/performance/nl-cache/src/nl-cache-helper.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/xlators/performance/nl-cache/src/nl-cache-helper.c b/xlators/performance/nl-cache/src/nl-cache-helper.c
index 4314038dcd9..03dedf8ea08 100644
--- a/xlators/performance/nl-cache/src/nl-cache-helper.c
+++ b/xlators/performance/nl-cache/src/nl-cache-helper.c
@@ -164,16 +164,19 @@ static int
nlc_inode_ctx_set(xlator_t *this, inode_t *inode, nlc_ctx_t *nlc_ctx,
nlc_pe_t *nlc_pe_p)
{
+ uint64_t ctx1, ctx2;
int ret = -1;
+ ctx1 = (uint64_t)(uintptr_t)nlc_ctx;
+ ctx2 = (uint64_t)(uintptr_t)nlc_pe_p;
+
/* The caller may choose to set one of the ctxs, hence check
* if the ctx1/2 is non zero and then send the address. If we
* blindly send the address of both the ctxs, it may reset the
* ctx the caller had sent NULL(intended as leave untouched) for.*/
LOCK(&inode->lock);
{
- ret = __inode_ctx_set2(inode, this, nlc_ctx ? (uint64_t *)&nlc_ctx : 0,
- nlc_pe_p ? (uint64_t *)&nlc_pe_p : 0);
+ ret = __inode_ctx_set2(inode, this, ctx1 ? &ctx1 : 0, ctx2 ? &ctx2 : 0);
}
UNLOCK(&inode->lock);
return ret;
@@ -285,6 +288,7 @@ out:
static nlc_ctx_t *
nlc_inode_ctx_get_set(xlator_t *this, inode_t *inode, nlc_ctx_t **nlc_ctx_p)
{
+ uint64_t ctx;
int ret = 0;
nlc_ctx_t *nlc_ctx = NULL;
nlc_conf_t *conf = NULL;
@@ -315,7 +319,8 @@ nlc_inode_ctx_get_set(xlator_t *this, inode_t *inode, nlc_ctx_t **nlc_ctx_p)
goto unlock;
}
- ret = __inode_ctx_set2(inode, this, (uint64_t *)&nlc_ctx, NULL);
+ ctx = (uint64_t)(uintptr_t)nlc_ctx;
+ ret = __inode_ctx_set2(inode, this, &ctx, NULL);
if (ret) {
gf_msg(this->name, GF_LOG_ERROR, ENOMEM, NLC_MSG_NO_MEMORY,
"inode ctx set failed");