From 74e8328d3f6901d6ba38a313965fe910c8411324 Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Thu, 1 Nov 2018 07:25:25 +0530 Subject: all: fix the format string exceptions Currently, there are possibilities in few places, where a user-controlled (like filename, program parameter etc) string can be passed as 'fmt' for printf(), which can lead to segfault, if the user's string contains '%s', '%d' in it. While fixing it, makes sense to make the explicit check for such issues across the codebase, by making the format call properly. Fixes: CVE-2018-14661 Fixes: bz#1644763 Change-Id: Ib547293f2d9eb618594cbff0df3b9c800e88bde4 Signed-off-by: Amar Tumballi --- xlators/features/barrier/src/barrier.c | 4 ++-- xlators/features/gfid-access/src/gfid-access.c | 2 +- xlators/features/locks/src/posix.c | 10 +++++----- xlators/features/quota/src/quota.c | 2 +- xlators/features/shard/src/shard.c | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) (limited to 'xlators/features') diff --git a/xlators/features/barrier/src/barrier.c b/xlators/features/barrier/src/barrier.c index edecae1a55e..1c5c5ffdc22 100644 --- a/xlators/features/barrier/src/barrier.c +++ b/xlators/features/barrier/src/barrier.c @@ -721,7 +721,7 @@ __barrier_dump_queue(barrier_priv_t *priv) list_for_each_entry(stub, &priv->queue, list) { snprintf(key, sizeof(key), "stub.%d", i++); - gf_proc_dump_add_section(key); + gf_proc_dump_add_section("%s", key); barrier_dump_stub(stub, key); } @@ -745,7 +745,7 @@ barrier_dump_priv(xlator_t *this) return 0; gf_proc_dump_build_key(key, "xlator.features.barrier", "priv"); - gf_proc_dump_add_section(key); + gf_proc_dump_add_section("%s", key); LOCK(&priv->lock); { diff --git a/xlators/features/gfid-access/src/gfid-access.c b/xlators/features/gfid-access/src/gfid-access.c index 68768eebf4e..0cf7870856b 100644 --- a/xlators/features/gfid-access/src/gfid-access.c +++ b/xlators/features/gfid-access/src/gfid-access.c @@ -1365,7 +1365,7 @@ ga_dump_inodectx(xlator_t *this, inode_t *inode) if (ret == 0) { tmp_inode = (void *)(uintptr_t)value; gf_proc_dump_build_key(key_prefix, this->name, "inode"); - gf_proc_dump_add_section(key_prefix); + gf_proc_dump_add_section("%s", key_prefix); gf_proc_dump_write("real-gfid", "%s", uuid_utoa(tmp_inode->gfid)); } diff --git a/xlators/features/locks/src/posix.c b/xlators/features/locks/src/posix.c index f08a22d4fc3..17f733a720e 100644 --- a/xlators/features/locks/src/posix.c +++ b/xlators/features/locks/src/posix.c @@ -3224,7 +3224,7 @@ __dump_entrylks(pl_inode_t *pl_inode) lock->connection_id, blocked, granted); } - gf_proc_dump_write(key, tmp); + gf_proc_dump_write(key, "%s", tmp); count++; } @@ -3242,7 +3242,7 @@ __dump_entrylks(pl_inode_t *pl_inode) lkowner_utoa(&lock->owner), lock->client, lock->connection_id, blocked); - gf_proc_dump_write(key, tmp); + gf_proc_dump_write(key, "%s", tmp); count++; } @@ -3286,7 +3286,7 @@ __dump_inodelks(pl_inode_t *pl_inode) lock->client, lock->connection_id, &lock->granted_time.tv_sec, &lock->blkd_time.tv_sec, _gf_true); - gf_proc_dump_write(key, tmp); + gf_proc_dump_write(key, "%s", tmp); count++; } @@ -3299,7 +3299,7 @@ __dump_inodelks(pl_inode_t *pl_inode) pl_dump_lock(tmp, sizeof(tmp), &lock->user_flock, &lock->owner, lock->client, lock->connection_id, 0, &lock->blkd_time.tv_sec, _gf_false); - gf_proc_dump_write(key, tmp); + gf_proc_dump_write(key, "%s", tmp); count++; } @@ -3334,7 +3334,7 @@ __dump_posixlks(pl_inode_t *pl_inode) lock->client, NULL, &lock->granted_time.tv_sec, &lock->blkd_time.tv_sec, (lock->blocked) ? _gf_false : _gf_true); - gf_proc_dump_write(key, tmp); + gf_proc_dump_write(key, "%s", tmp); count++; } diff --git a/xlators/features/quota/src/quota.c b/xlators/features/quota/src/quota.c index 0b81e370e43..eb461f4ad22 100644 --- a/xlators/features/quota/src/quota.c +++ b/xlators/features/quota/src/quota.c @@ -5125,7 +5125,7 @@ quota_priv_dump(xlator_t *this) if (!priv) goto out; - gf_proc_dump_add_section("xlators.features.quota.priv", this->name); + gf_proc_dump_add_section("xlators.features.quota.priv"); ret = TRY_LOCK(&priv->lock); if (ret) diff --git a/xlators/features/shard/src/shard.c b/xlators/features/shard/src/shard.c index 79804bdeadd..b63236884d3 100644 --- a/xlators/features/shard/src/shard.c +++ b/xlators/features/shard/src/shard.c @@ -6759,12 +6759,12 @@ shard_priv_dump(xlator_t *this) priv = this->private; snprintf(key_prefix, GF_DUMP_MAX_BUF_LEN, "%s.%s", this->type, this->name); - gf_proc_dump_add_section(key_prefix); + gf_proc_dump_add_section("%s", key_prefix); str = gf_uint64_2human_readable(priv->block_size); gf_proc_dump_write("shard-block-size", "%s", str); gf_proc_dump_write("inode-count", "%d", priv->inode_count); gf_proc_dump_write("ilist_head", "%p", &priv->ilist_head); - gf_proc_dump_write("lru-max-limit", "%d", priv->lru_limit); + gf_proc_dump_write("lru-max-limit", "%" PRIu64, priv->lru_limit); GF_FREE(str); -- cgit