ldb: Don't wrongly claim to return message elements
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Thu, 26 Jan 2023 19:02:18 +0000 (08:02 +1300)
committerAndreas Schneider <asn@cryptomilk.org>
Wed, 12 Apr 2023 13:52:31 +0000 (13:52 +0000)
If the LDB_UNPACK_DATA_FLAG_NO_ATTRS flag is set, we don't return any
elements, so we should set num_elements accordingly. This ensures
callers don't try to access elements that aren't there.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andreas Schneider <asn@samba.org>
lib/ldb/common/ldb_pack.c

index 4d32d951a8334e1752f606e428c385079c41ec7d..490e7726d4dcd3a0274358ca32456249e66866fc 100644 (file)
@@ -610,6 +610,7 @@ static int ldb_unpack_data_flags_v1(struct ldb_context *ldb,
        }
 
        if (flags & LDB_UNPACK_DATA_FLAG_NO_ATTRS) {
+               message->num_elements = 0;
                return 0;
        }
        
@@ -838,6 +839,7 @@ static int ldb_unpack_data_flags_v2(struct ldb_context *ldb,
        }
 
        if (flags & LDB_UNPACK_DATA_FLAG_NO_ATTRS) {
+               message->num_elements = 0;
                return 0;
        }