s3:lib: Use memcpy() in escape_ldap_string()
authorAndreas Schneider <asn@samba.org>
Wed, 9 May 2018 15:29:39 +0000 (17:29 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Thu, 17 May 2018 15:30:09 +0000 (17:30 +0200)
../source3/lib/ldap_escape.c: In function ‘escape_ldap_string’:
../source3/lib/ldap_escape.c:79:4: error: ‘strncpy’ output truncated
    before terminating nul copying 3 bytes from a string of the same length
[-Werror=stringop-truncation]
    strncpy (p, sub, 3);
    ^~~~~~~~~~~~~~~~~~~

We concatenat and do not care about NUL-termination till the loop has
finished.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13437

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
source3/lib/ldap_escape.c

index fa75dabcae68db2c90ef6f7749ce140073254faa..0d2b8f5fe018bcd08908cf619cee607e074ae0ee 100644 (file)
@@ -76,7 +76,7 @@ char *escape_ldap_string(TALLOC_CTX *mem_ctx, const char *s)
                        output = tmp;
 
                        p = &output[i];
-                       strncpy (p, sub, 3);
+                       memcpy(p, sub, 3);
                        p += 3;
                        i += 3;