From 748589e789c580140b576b498844cca2788d06d8 Mon Sep 17 00:00:00 2001 From: Lukas Slebodnik Date: Fri, 1 Jul 2016 23:18:46 +0200 Subject: [PATCH 1/2] 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. --- src/tests/cmocka/test_sysdb_ts_cache.c | 7 +++++-- 1 file 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 e04daee1fc38ab454158b6067a967a44fbc0d2dd..c76dd1e8e6c40310076c7e6831713eeedd169286 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); -- 2.7.4