diff options
author | Joseph Sutton <josephsutton@catalyst.net.nz> | 2023-03-03 17:26:04 +1300 |
---|---|---|
committer | Jule Anger <janger@samba.org> | 2023-03-20 10:03:50 +0100 |
commit | 15723d6ff5eaa7f8e7e2803ffeab97f36289f2fe (patch) | |
tree | 8f234f5850f0160bf63c40c79c15944cf1db8732 | |
parent | 78a7b155cc2b50d5dea8a3e0588f646100ea0a92 (diff) | |
download | samba-15723d6ff5eaa7f8e7e2803ffeab97f36289f2fe.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>
-rw-r--r-- | lib/ldb/common/ldb_msg.c | 16 | ||||
-rw-r--r-- | lib/ldb/include/ldb_private.h | 3 |
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 7d9a47c8ef3..f6f47c28cf3 100644 --- a/lib/ldb/include/ldb_private.h +++ b/lib/ldb/include/ldb_private.h @@ -317,6 +317,9 @@ 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); + /** * @brief Convert a character to uppercase with ASCII precedence. * |