From: Martin Schwenke Date: Thu, 26 Jul 2018 01:00:28 +0000 (+1000) Subject: ctdb-common: Fix compilation issue with strncpy() X-Git-Tag: ldb-1.5.0~163 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5dd84bf5d73e4afab094834bc317da7884b9b9b3;p=thirdparty%2Fsamba.git ctdb-common: Fix compilation issue with strncpy() 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 --- diff --git a/ctdb/common/system_socket.c b/ctdb/common/system_socket.c index d8627fd61fc..843e5d74816 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);