summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Sutton <josephsutton@catalyst.net.nz>2023-03-03 17:26:04 +1300
committerJule Anger <janger@samba.org>2023-03-20 10:03:38 +0100
commit873d4e465f333c487dc1bee748054b6b606c299b (patch)
tree70eb1617b888a9733723ade3987821dc1a18d7e2
parent891ffeaf99d150e2a5707d71825e5533570aa974 (diff)
downloadsamba-873d4e465f333c487dc1bee748054b6b606c299b.tar.gz
CVE-2023-0614 ldb: Add function to remove excess capacity from an ldb message
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]
-rw-r--r--lib/ldb/common/ldb_msg.c16
-rw-r--r--lib/ldb/include/ldb_private.h3
2 files changed, 19 insertions, 0 deletions
diff --git a/lib/ldb/common/ldb_msg.c b/lib/ldb/common/ldb_msg.c
index cbc7e32b2ba..2ea2cce2e83 100644
--- a/lib/ldb/common/ldb_msg.c
+++ b/lib/ldb/common/ldb_msg.c
@@ -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
*/
diff --git a/lib/ldb/include/ldb_private.h b/lib/ldb/include/ldb_private.h
index 4deb24691ca..338e71def6d 100644
--- a/lib/ldb/include/ldb_private.h
+++ b/lib/ldb/include/ldb_private.h
@@ -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