From e3cf7302749db26153846cd47d29f5d2b5c6218a Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Thu, 26 Jul 2018 11:00:28 +1000 Subject: [PATCH 1/2] ctdb-common: Fix compilation issue with strncpy() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When configured with --picky-developer and using -O3 with gcc 8.1: ../common/system_socket.c: In function ‘parse_ip_mask’: ../common/system_socket.c:229:2: error: ‘strncpy’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=] strncpy(s, str, len+1); ^~~~~~~~~~~~~~~~~~~~~~ ../common/system_socket.c:223: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 (cherry picked from commit 5dd84bf5d73e4afab094834bc317da7884b9b9b3) --- ctdb/common/system_socket.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ctdb/common/system_socket.c b/ctdb/common/system_socket.c index 4e43805ca38..62cc782a224 100644 --- a/ctdb/common/system_socket.c +++ b/ctdb/common/system_socket.c @@ -220,14 +220,12 @@ bool parse_ip_mask(const char *str, ZERO_STRUCT(*addr); - len = strlen(str); + len = strlcpy(s, str, sizeof(s)); if (len >= sizeof(s)) { DBG_ERR("Address %s is unreasonably long\n", str); return false; } - strncpy(s, str, len+1); - p = rindex(s, '/'); if (p == NULL) { DBG_ERR("Address %s does not contain a mask\n", s); -- 2.17.1 From d721507005204129f7f36c76e05ece0138a9d6fd Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Thu, 26 Jul 2018 11:01:30 +1000 Subject: [PATCH 2/2] ctdb-protocol: Fix compilation issue with strncpy() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 (cherry picked from commit 3b56f2002a35b55b46958178c79aee519f0c5880) --- ctdb/protocol/protocol_util.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ctdb/protocol/protocol_util.c b/ctdb/protocol/protocol_util.c index 77e79867443..a0127a643bc 100644 --- a/ctdb/protocol/protocol_util.c +++ b/ctdb/protocol/protocol_util.c @@ -276,13 +276,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; -- 2.17.1