The branch, master has been updated
       via  4b3de61 ldb/tests: more thoroughly test empty ldb_msg elements
       via  282410f ldb: avoid searching empty lists in 
ldb_msg_find_common_values
       via  963d9f1 ldb: Fix index out of bound in ldb_msg_find_common_values
      from  b21ee14 s3: tests: Add test for new smbclient "deltree" command.

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 4b3de6118569eb9a1d4f233eca112d0d207c1087
Author: Douglas Bagnall <[email protected]>
Date:   Thu Jul 6 12:41:07 2017 +1200

    ldb/tests: more thoroughly test empty ldb_msg elements
    
    Signed-off-by: Douglas Bagnall <[email protected]>
    Reviewed-by: Andreas Schneider <[email protected]>
    
    Autobuild-User(master): Andreas Schneider <[email protected]>
    Autobuild-Date(master): Fri Jul  7 20:10:37 CEST 2017 on sn-devel-144

commit 282410fa2416404962521ad6b2598a9c83b63594
Author: Douglas Bagnall <[email protected]>
Date:   Thu Jul 6 10:01:24 2017 +1200

    ldb: avoid searching empty lists in ldb_msg_find_common_values
    
    Signed-off-by: Douglas Bagnall <[email protected]>
    Reviewed-by: Andreas Schneider <[email protected]>

commit 963d9f12f902ae266a8c7edbf4249090de46173b
Author: Lukas Slebodnik <[email protected]>
Date:   Tue Jul 4 15:46:49 2017 +0200

    ldb: Fix index out of bound in ldb_msg_find_common_values
    
    cmocka unit test failed on i386
    [==========] Running 2 test(s).
    [ RUN      ] test_ldb_msg_find_duplicate_val
    [       OK ] test_ldb_msg_find_duplicate_val
    [ RUN      ] test_ldb_msg_find_common_values
    [  FAILED  ] test_ldb_msg_find_common_values
    [==========] 2 test(s) run.
    [  ERROR   ] --- 0x14 != 0
    [   LINE   ] --- ../tests/ldb_msg.c:266: error: Failure!
    [  PASSED  ] 1 test(s).
    [  FAILED  ] 1 test(s), listed below:
    [  FAILED  ] test_ldb_msg_find_common_values
     1 FAILED TEST(S)
    
    But we were just lucky on other platforms because there is
    index out of bound according to valgrind error.
    
    ==3298== Invalid read of size 4
    ==3298==    at 0x486FCF6: ldb_val_cmp (ldb_msg.c:95)
    ==3298==    by 0x486FCF6: ldb_msg_find_common_values (ldb_msg.c:266)
    ==3298==    by 0x109A3D: test_ldb_msg_find_common_values (ldb_msg.c:265)
    ==3298==    by 0x48E7490: ??? (in /usr/lib/libcmocka.so.0.4.1)
    ==3298==    by 0x48E7EB0: _cmocka_run_group_tests (in 
/usr/lib/libcmocka.so.0.4.1)
    ==3298==    by 0x1089B7: main (ldb_msg.c:352)
    ==3298==  Address 0x4b07734 is 4 bytes after a block of size 48 alloc'd
    ==3298==    at 0x483223E: malloc (vg_replace_malloc.c:299)
    ==3298==    by 0x4907AA7: _talloc_array (in /usr/lib/libtalloc.so.2.1.9)
    ==3298==    by 0x486FBF8: ldb_msg_find_common_values (ldb_msg.c:245)
    ==3298==    by 0x109A3D: test_ldb_msg_find_common_values (ldb_msg.c:265)
    ==3298==    by 0x48E7490: ??? (in /usr/lib/libcmocka.so.0.4.1)
    ==3298==    by 0x48E7EB0: _cmocka_run_group_tests (in 
/usr/lib/libcmocka.so.0.4.1)
    ==3298==    by 0x1089B7: main (ldb_msg.c:352)
    
    Signed-off-by: Lukas Slebodnik <[email protected]>
    Reviewed-by: Douglas Bagnall <[email protected]>
    Reviewed-by: Andreas Schneider <[email protected]>

-----------------------------------------------------------------------

Summary of changes:
 lib/ldb/common/ldb_msg.c | 13 ++++---------
 lib/ldb/tests/ldb_msg.c  | 32 +++++++++++++++++++++++++++++---
 2 files changed, 33 insertions(+), 12 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/ldb/common/ldb_msg.c b/lib/ldb/common/ldb_msg.c
index abad5a8..c2782db 100644
--- a/lib/ldb/common/ldb_msg.c
+++ b/lib/ldb/common/ldb_msg.c
@@ -207,6 +207,9 @@ int ldb_msg_find_common_values(struct ldb_context *ldb,
        if (strcmp(el->name, el2->name) != 0) {
                return LDB_ERR_INAPPROPRIATE_MATCHING;
        }
+       if (el->num_values == 0 || el2->num_values == 0) {
+               return LDB_SUCCESS;
+       }
        /*
           With few values, it is better to do the brute-force search than the
           clever search involving tallocs, memcpys, sorts, etc.
@@ -262,20 +265,12 @@ int ldb_msg_find_common_values(struct ldb_context *ldb,
        n_values = el->num_values;
        i = 0;
        j = 0;
-       while (i != n_values) {
+       while (i != n_values && j < el2->num_values) {
                int ret = ldb_val_cmp(&values[i], &values2[j]);
                if (ret < 0) {
                        i++;
                } else if (ret > 0) {
                        j++;
-                       if (j == el2->num_values) {
-                               /*
-                                 We have walked past the end of the second
-                                 list, meaning the remainder of the first
-                                 list cannot collide and we're done.
-                               */
-                               break;
-                       }
                } else {
                        /* we have a collision */
                        if (! remove_duplicates) {
diff --git a/lib/ldb/tests/ldb_msg.c b/lib/ldb/tests/ldb_msg.c
index e665d55..f8de418 100644
--- a/lib/ldb/tests/ldb_msg.c
+++ b/lib/ldb/tests/ldb_msg.c
@@ -87,6 +87,11 @@ static void test_ldb_msg_find_duplicate_val(void **state)
        ret = ldb_msg_add_empty(msg, "el1", 0, &el);
        assert_int_equal(ret, LDB_SUCCESS);
 
+       /* An empty message contains no duplicates */
+       ret = ldb_msg_find_duplicate_val(NULL, test_ctx, el, &dupe, 0);
+       assert_int_equal(ret, LDB_SUCCESS);
+       assert_null(dupe);
+
        for (i = 0; i < 5; i++) {
                add_uint_value(test_ctx, msg, "el1", i);
        }
@@ -176,19 +181,19 @@ static void _assert_element_equal(struct 
ldb_message_element *a,
 static void test_ldb_msg_find_common_values(void **state)
 {
        /* we only use the state as a talloc context */
-       struct ldb_message_element *el, *el2, *el3, *el4, *el2b;
+       struct ldb_message_element *el, *el2, *el3, *el4, *el2b, *empty;
        struct ldb_message_element *orig, *orig2, *orig3, *orig4;
        int ret;
        const uint32_t remove_dupes = LDB_MSG_FIND_COMMON_REMOVE_DUPLICATES;
        el = new_msg_element(*state, "test", 0, 4);
        el2 = new_msg_element(*state, "test", 4, 4);
        el3 = new_msg_element(*state, "test", 6, 4);
+       empty = new_msg_element(*state, "test", 0, 0);
        orig = new_msg_element(*state, "test", 0, 4);
        orig2 = new_msg_element(*state, "test", 4, 4);
        orig3 = new_msg_element(*state, "test", 6, 4);
 
        /* first round is with short value arrays, using quadratic method */
-
        /* we expect no collisions here */
        ret = ldb_msg_find_common_values(NULL, *state, el, el2, 0);
        assert_int_equal(ret, LDB_SUCCESS);
@@ -256,7 +261,7 @@ static void test_ldb_msg_find_common_values(void **state)
        assert_element_equal(el2, orig2);
        assert_int_equal(el3->num_values, 0);
 
-       /* seeing as we have an empty element, try permutations therewith.
+       /* permutations involving empty elements.
           everything should succeed. */
        ret = ldb_msg_find_common_values(NULL, *state, el3, el2, 0);
        assert_int_equal(ret, LDB_SUCCESS);
@@ -264,10 +269,19 @@ static void test_ldb_msg_find_common_values(void **state)
        assert_int_equal(ret, LDB_SUCCESS);
        ret = ldb_msg_find_common_values(NULL, *state, el2, el3, 0);
        assert_int_equal(ret, LDB_SUCCESS);
+       assert_int_equal(el2->num_values, orig2->num_values);
        ret = ldb_msg_find_common_values(NULL, *state, el3, el2, remove_dupes);
        assert_int_equal(ret, LDB_SUCCESS);
+       assert_int_equal(el2->num_values, orig2->num_values);
+       assert_int_equal(el3->num_values, 0); /* el3 is now empty */
        ret = ldb_msg_find_common_values(NULL, *state, el2, el3, remove_dupes);
        assert_int_equal(ret, LDB_SUCCESS);
+       ret = ldb_msg_find_common_values(NULL, *state, el3, empty, 0);
+       assert_int_equal(ret, LDB_SUCCESS);
+       ret = ldb_msg_find_common_values(NULL, *state, empty, empty, 0);
+       assert_int_equal(ret, LDB_SUCCESS);
+       ret = ldb_msg_find_common_values(NULL, *state, empty, el3, 0);
+       assert_int_equal(ret, LDB_SUCCESS);
 
        assert_element_equal(el2, orig2);
        assert_element_equal(el, orig);
@@ -329,6 +343,18 @@ static void test_ldb_msg_find_common_values(void **state)
        orig2 = new_msg_element(*state, "test", 12, 2);
        assert_element_equal(el2, orig2);
 
+       /* test the empty el against the full elements */
+       ret = ldb_msg_find_common_values(NULL, *state, el, empty, 0);
+       assert_int_equal(ret, LDB_SUCCESS);
+       ret = ldb_msg_find_common_values(NULL, *state, empty, el, 0);
+       assert_int_equal(ret, LDB_SUCCESS);
+       ret = ldb_msg_find_common_values(NULL, *state, el, empty, remove_dupes);
+       assert_int_equal(ret, LDB_SUCCESS);
+       ret = ldb_msg_find_common_values(NULL, *state, empty, el, remove_dupes);
+       assert_int_equal(ret, LDB_SUCCESS);
+       assert_element_equal(el, orig);
+       assert_element_equal(empty, el3);
+
        /* make sure an identical element with a different name is rejected */
        el2 = new_msg_element(*state, "fish", 12, 2);
        ret = ldb_msg_find_common_values(NULL, *state, el2, el, remove_dupes);


-- 
Samba Shared Repository

Reply via email to