ctdb-common: Fix compilation issue with strncpy()
authorMartin Schwenke <martin@meltin.net>
Thu, 26 Jul 2018 01:00:28 +0000 (11:00 +1000)
committerAmitay Isaacs <amitay@samba.org>
Fri, 27 Jul 2018 03:45:20 +0000 (05:45 +0200)
commit5dd84bf5d73e4afab094834bc317da7884b9b9b3
treef8074d405a70d2dba704942943a213f9239adfb3
parent2dffcde408008d2bbac8e796ea7ce770c7e97f63
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 <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/common/system_socket.c