[SSSD] [PATCH] sdap-tests: Fix off by one

Lukas Slebodnik lslebodn at redhat.com
Wed Jul 9 11:02:39 UTC 2014


ehlo,

1st patch fix valgrind warning
2nd patch fix linking of sdap-tests on platfrms with disabled link_all_deplibs

LS
-------------- next part --------------
>From b7054af6a9298fe46d7828d5132ba3a3453b617c Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn at redhat.com>
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

-------------- next part --------------
>From 53f8fae8132951eea126f90af329de33249e82a6 Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn at redhat.com>
Date: Wed, 9 Jul 2014 12:47:55 +0200
Subject: [PATCH 2/2] BUILD: Link sdap-tests with openldap libraries

sdap-tests uses functions from openldap, but it was not linked with libldap or
liblber.

sh-4.2$ nm --undefined-only .libs/sdap-tests | grep -E "ldap|ber"
                 U ber_free
                 U ldap_control_create
                 U ldap_err2string
                 U ldap_get_option
                 U ldap_init_fd
                 U ldap_install_tls
                 U ldap_is_ldaps_url
                 U ldap_unbind_ext

sdap-tests cannot be linked on platfrms with disabled link_all_deplibs.

  CCLD     sdap-tests
/usr/bin/ld: src/providers/ldap/sdap_tests-sdap.o: undefined reference to symbol 'ber_free'
/usr/bin/ld: note: 'ber_free' is defined in DSO /lib64/liblber-2.4.so.2 so try adding it to the linker command line
/lib64/liblber-2.4.so.2: could not read symbols: Invalid operation
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [sdap-tests] Error 1
---
 Makefile.am | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Makefile.am b/Makefile.am
index 32af6c0696384c2c91b7d4a7dbef1b84e925846c..04bfeeb2f92284aa54864bea39fb79a62cabfe3b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1878,6 +1878,7 @@ sdap_tests_LDADD = \
     $(POPT_LIBS) \
     $(SSSD_INTERNAL_LTLIBS) \
     $(SSS_CRYPT_LIBS) \
+    $(OPENLDAP_LIBS) \
     libsss_test_common.la \
     $(NULL)
 
-- 
1.9.3



More information about the sssd-devel mailing list