From: Ralph Boehme Date: Tue, 30 Jul 2019 13:39:38 +0000 (+0200) Subject: s3:mdssvc: avoid strncpy when marshalling strings X-Git-Tag: tdb-1.4.2~222 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=25c5012c53f4d8efbe04ee8d3c8af256fec592a7;p=thirdparty%2Fsamba.git s3:mdssvc: avoid strncpy when marshalling strings Avoids failure when at O3 level: [2082/4232] Compiling source3/rpc_server/mdssvc/marshalling.c ==> /builds/samba-team/devel/samba/samba-o3.stderr <== In file included from /usr/include/string.h:494, from /usr/include/bsd/string.h:30, from ../../lib/tevent/../replace/replace.h:164, from ../../source3/include/includes.h:23, from ../../source3/rpc_server/mdssvc/marshalling.c:21: In function ‘strncpy’, inlined from ‘sl_pack_string’ at ../../source3/rpc_server/mdssvc/marshalling.c:493:2, inlined from ‘sl_pack_loop’ at ../../source3/rpc_server/mdssvc/marshalling.c:607:13: /usr/include/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation] 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../source3/rpc_server/mdssvc/marshalling.c: In function ‘sl_pack_loop’: ../../source3/rpc_server/mdssvc/marshalling.c:458:8: note: length computed here 458 | len = strlen(s); | ^~~~~~~~~ cc1: all warnings being treated as errors Marshalled strings are not 0 terminated. Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- diff --git a/source3/rpc_server/mdssvc/marshalling.c b/source3/rpc_server/mdssvc/marshalling.c index b5931c7f060..eee1cd93010 100644 --- a/source3/rpc_server/mdssvc/marshalling.c +++ b/source3/rpc_server/mdssvc/marshalling.c @@ -490,7 +490,7 @@ static ssize_t sl_pack_string(char *s, char *buf, ssize_t offset, size_t bufsize } memset(buf + offset, 0, octets * 8); - strncpy(buf + offset, s, len); + memcpy(buf + offset, s, len); offset += octets * 8; return offset;