]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ldb:ldb_pack: filter avoids looping over msg when attrs contain "*"
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Fri, 26 Jul 2024 03:47:03 +0000 (15:47 +1200)
committerDouglas Bagnall <dbagnall@samba.org>
Thu, 19 Dec 2024 23:00:32 +0000 (23:00 +0000)
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
lib/ldb/common/ldb_pack.c

index 4c2052372be5b86f7987d5b184af017309b10d2b..409be59061159dacb0dd8805a7ddc612a7bdbf2e 100644 (file)
@@ -1294,19 +1294,23 @@ int ldb_filter_attrs_in_place(struct ldb_message *msg,
                keep_all = true;
        }
 
+       if (keep_all) {
+               return LDB_SUCCESS;
+       }
+       /*
+        * Find the intersection between the msg elements and attrs.
+        *
+        * TODO, maybe: use a faster algorithm when (n * m) is too large.
+        */
        for (i = 0; i < msg->num_elements; i++) {
                bool found = false;
                unsigned int j;
 
-               if (keep_all) {
-                       found = true;
-               } else {
-                       for (j = 0; attrs[j]; j++) {
-                               int cmp = ldb_attr_cmp(msg->elements[i].name, attrs[j]);
-                               if (cmp == 0) {
-                                       found = true;
-                                       break;
-                               }
+               for (j = 0; attrs[j]; j++) {
+                       int cmp = ldb_attr_cmp(msg->elements[i].name, attrs[j]);
+                       if (cmp == 0) {
+                               found = true;
+                               break;
                        }
                }