ldb_msg: Don't fail in ldb_msg_copy() if source DN is NULL
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Mon, 13 Sep 2021 23:08:41 +0000 (11:08 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 15 Sep 2021 07:59:31 +0000 (07:59 +0000)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14642
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14836

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
lib/ldb/common/ldb_msg.c

index 0179c35659bdc16a8a6ff3521fb262e6f3728be2..57dfc5a04c2b3f08c3a8535cc2569f44b9efb5e8 100644 (file)
@@ -876,8 +876,10 @@ struct ldb_message *ldb_msg_copy(TALLOC_CTX *mem_ctx,
        msg2 = ldb_msg_copy_shallow(mem_ctx, msg);
        if (msg2 == NULL) return NULL;
 
-       msg2->dn = ldb_dn_copy(msg2, msg2->dn);
-       if (msg2->dn == NULL) goto failed;
+       if (msg2->dn != NULL) {
+               msg2->dn = ldb_dn_copy(msg2, msg2->dn);
+               if (msg2->dn == NULL) goto failed;
+       }
 
        for (i=0;i<msg2->num_elements;i++) {
                struct ldb_message_element *el = &msg2->elements[i];