]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
CVE-2023-0614 ldb: Add function to remove excess capacity from an ldb message
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Fri, 3 Mar 2023 04:26:04 +0000 (17:26 +1300)
committerJule Anger <janger@samba.org>
Mon, 20 Mar 2023 09:03:38 +0000 (10:03 +0100)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15270

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
[abartlet@samba.org Adapted to conflict from lack of new
ldb_ascii_toupper() in ldb_private.h]

lib/ldb/common/ldb_msg.c
lib/ldb/include/ldb_private.h

index cbc7e32b2ba668390feaebc3c718b0ae0e495d57..2ea2cce2e833ef74eba4b266cd0b7476985b7d70 100644 (file)
@@ -1497,6 +1497,22 @@ void ldb_msg_remove_attr(struct ldb_message *msg, const char *attr)
        }
 }
 
+/* Reallocate elements to drop any excess capacity. */
+void ldb_msg_shrink_to_fit(struct ldb_message *msg)
+{
+       if (msg->num_elements > 0) {
+               struct ldb_message_element *elements = talloc_realloc(msg,
+                                                                     msg->elements,
+                                                                     struct ldb_message_element,
+                                                                     msg->num_elements);
+               if (elements != NULL) {
+                       msg->elements = elements;
+               }
+       } else {
+               TALLOC_FREE(msg->elements);
+       }
+}
+
 /*
   return a LDAP formatted GeneralizedTime string
 */
index 4deb24691ca08f037a1d6b865e1cdfcf0c393319..338e71def6da99239b6036ff716ba0d655448447 100644 (file)
@@ -317,4 +317,7 @@ int ldb_match_message(struct ldb_context *ldb,
                      const struct ldb_parse_tree *tree,
                      enum ldb_scope scope, bool *matched);
 
+/* Reallocate elements to drop any excess capacity. */
+void ldb_msg_shrink_to_fit(struct ldb_message *msg);
+
 #endif