summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Slebodnik <lslebodn@redhat.com>2016-07-01 23:18:46 +0200
committerJakub Hrozek <jhrozek@redhat.com>2016-07-06 17:27:25 +0200
commitc7c1941f9045531044121520fc2ca0e048732c25 (patch)
tree81d26f995612ea6476a0f7cfafa3930d3c647269
parent5e843d18e161057966e0ef4d303774b93fe56139 (diff)
downloadsssd-c7c1941f9045531044121520fc2ca0e048732c25.tar.gz
sssd-c7c1941f9045531044121520fc2ca0e048732c25.tar.xz
sssd-c7c1941f9045531044121520fc2ca0e048732c25.zip
test_sysdb_ts_cache: Do not use wrong pointer for output argument
The function sysdb_search_groups expects pointer to size_t as an output argument msgs_count. However, struct ldb_result has type unsigned for element count. The size of unsigned is lower then size of size_t on some platforms. Therefore we should not cast to pointer to size_t if we want to write count of messages into struct ldb_result -> count. The valgrind did not detect write out of boundary for the element count because it is the 1st element in structure ldb_result. It didn't cause any problem on little endian because the most significant part of size_t was properly stored to type unsigned. We firstly store to output argument _msgs_count and then to output argument _msgs in the function sysdb_cache_search_entry therefore element msgs was not damaged and contained correct data. Reviewed-by: Sumit Bose <sbose@redhat.com>
-rw-r--r--src/tests/cmocka/test_sysdb_ts_cache.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/tests/cmocka/test_sysdb_ts_cache.c b/src/tests/cmocka/test_sysdb_ts_cache.c
index e04daee1f..c76dd1e8e 100644
--- a/src/tests/cmocka/test_sysdb_ts_cache.c
+++ b/src/tests/cmocka/test_sysdb_ts_cache.c
@@ -795,6 +795,7 @@ static void test_merge_ldb_results(void **state)
struct ldb_result *res;
struct ldb_result *res1;
struct ldb_result *res2;
+ size_t msgs_count;
res1 = talloc_zero(test_ctx, struct ldb_result);
assert_non_null(res1);
@@ -831,7 +832,8 @@ static void test_merge_ldb_results(void **state)
assert_non_null(filter);
ret = sysdb_search_groups(res1, test_ctx->tctx->dom,
filter, gr_fetch_attrs,
- (size_t *) &res1->count, &res1->msgs);
+ &msgs_count, &res1->msgs);
+ res1->count = (unsigned)msgs_count;
talloc_free(filter);
assert_int_equal(ret, EOK);
assert_int_equal(res1->count, 2);
@@ -842,7 +844,8 @@ static void test_merge_ldb_results(void **state)
assert_non_null(filter);
ret = sysdb_search_groups(res2, test_ctx->tctx->dom,
filter, gr_fetch_attrs,
- (size_t *) &res2->count, &res2->msgs);
+ &msgs_count, &res2->msgs);
+ res2->count = (unsigned)msgs_count;
talloc_free(filter);
assert_int_equal(ret, EOK);
assert_int_equal(res2->count, 2);