From: Martin Schwenke Date: Thu, 26 Jul 2018 01:01:30 +0000 (+1000) Subject: ctdb-protocol: Fix compilation issue with strncpy() X-Git-Tag: ldb-1.5.0~162 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3b56f2002a35b55b46958178c79aee519f0c5880;p=thirdparty%2Fsamba.git ctdb-protocol: Fix compilation issue with strncpy() When configured with --picky-developer and using -O3 with gcc 8.1: ../protocol/protocol_util.c: In function ‘ctdb_sock_addr_from_string’: ../protocol/protocol_util.c:282:2: error: ‘strncpy’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=] strncpy(s, str, len+1); ^~~~~~~~~~~~~~~~~~~~~~ ../protocol/protocol_util.c:277:8: note: length computed here len = strlen(str); ^~~~~~~~~~~ Use strlcpy() instead and check the result. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13545 Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/protocol/protocol_util.c b/ctdb/protocol/protocol_util.c index c75555fa734..1b9a46ef8e2 100644 --- a/ctdb/protocol/protocol_util.c +++ b/ctdb/protocol/protocol_util.c @@ -274,13 +274,11 @@ int ctdb_sock_addr_from_string(const char *str, /* Parse out port number and then IP address */ - len = strlen(str); + len = strlcpy(s, str, sizeof(s)); if (len >= sizeof(s)) { return EINVAL; } - strncpy(s, str, len+1); - p = rindex(s, ':'); if (p == NULL) { return EINVAL;