>From b7054af6a9298fe46d7828d5132ba3a3453b617c Mon Sep 17 00:00:00 2001 From: Lukas Slebodnik Date: Wed, 9 Jul 2014 11:42:46 +0200 Subject: [PATCH 1/2] sdap-tests: Fix off by one. Function sss_base64_decode does not return NUL terminated string and it causes valgrind warning in test "Invalid read of size 1" ==30954== Invalid read of size 1 ==30954== at 0x4A09FB8: strcmp (mc_replace_strmem.c:730) ==30954== by 0x4C2AAFA: _assert_string_equal (in /usr/lib64/libcmocka.so.0.2.1) ==30954== by 0x407DBA: test_parse_with_map (test_sdap.c:285) ==30954== by 0x4C2C817: _run_test (in /usr/lib64/libcmocka.so.0.2.1) ==30954== by 0x4C2CCF8: _run_tests (in /usr/lib64/libcmocka.so.0.2.1) ==30954== by 0x408A6F: main (test_sdap.c:583) ==30954== Address 0x6a8db34 is 0 bytes after a block of size 100 alloc'd ==30954== at 0x4A0645D: malloc (vg_replace_malloc.c:291) ==30954== by 0x35C8204980: _talloc_memdup (talloc.c:613) ==30954== by 0x5080A4B: sss_base64_decode (nss_base64.c:86) ==30954== by 0x407DA0: test_parse_with_map (test_sdap.c:282) ==30954== by 0x4C2C817: _run_test (in /usr/lib64/libcmocka.so.0.2.1) ==30954== by 0x4C2CCF8: _run_tests (in /usr/lib64/libcmocka.so.0.2.1) ==30954== by 0x408A6F: main (test_sdap.c:583) --- src/tests/cmocka/test_sdap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tests/cmocka/test_sdap.c b/src/tests/cmocka/test_sdap.c index 33cefcc88b3a1c662751c463cc44c19526d77169..f61c38c5fa75cd77749cb2920681c19800ffbc87 100644 --- a/src/tests/cmocka/test_sdap.c +++ b/src/tests/cmocka/test_sdap.c @@ -282,7 +282,8 @@ void test_parse_with_map(void **state) decoded_key = sss_base64_decode(test_ctx, (const char *)el->values[0].data, &key_len); - assert_string_equal(decoded_key, "1234"); + assert_non_null(decoded_key); + assert_memory_equal(decoded_key, "1234", key_len); /* The extra attribute must not be downloaded, it's not present in map */ assert_entry_has_no_attr(attrs, "extra"); -- 1.9.3