tldap: Make memcpy of no controls safe
authorGarming Sam <garming@catalyst.net.nz>
Wed, 31 Jul 2019 01:08:23 +0000 (01:08 +0000)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 1 Aug 2019 05:01:15 +0000 (05:01 +0000)
Static analyzers sometimes complain about this case.

Signed-off-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14029

source3/lib/tldap_util.c

index 152942dab2c4ecc6b4983f89a545448d109e3a72..bdf8eb031a5a59035be366b12cc47192659b68d0 100644 (file)
@@ -588,7 +588,9 @@ struct tldap_control *tldap_add_control(TALLOC_CTX *mem_ctx,
        if (result == NULL) {
                return NULL;
        }
-       memcpy(result, ctrls, sizeof(struct tldap_control) * num_ctrls);
+       if (num_ctrls > 0) {
+               memcpy(result, ctrls, sizeof(struct tldap_control) * num_ctrls);
+       }
        result[num_ctrls] = *ctrl;
        return result;
 }