zdev: Copy strings correctly using util_strlcpy()

Make sure strings are copied correctly by using util_strlcpy().

Also, rename the NIC_{OWNER,NAME}_LEN definitions to *_SIZE to make it
more clear that the terminating null byte ('\0') is included in this
buffer size. Using *_LEN would mean only the number of characters in the
string fit in.
Furthermore, use these definitions rather than sizeof().

This fixes the following GCC8 compile warning:

nic.c: In function ‘nic_data_get’:
nic.c:58:2: warning: ‘strncpy’ specified bound 9 equals destination size
[-Wstringop-truncation]
  strncpy(data.owner, argv[11], sizeof(data.owner));
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nic.c:59:2: warning: ‘strncpy’ specified bound 9 equals destination size
[-Wstringop-truncation]
  strncpy(data.name, argv[12], sizeof(data.name));
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Jan Höppner
2018-10-22 17:09:10 +02:00
parent d85cf20981
commit d14051e309
2 changed files with 8 additions and 6 deletions

View File

@@ -10,6 +10,8 @@
#include <stdlib.h>
#include <string.h>
#include "lib/util_libc.h"
#include "misc.h"
#include "nic.h"
#include "path.h"
@@ -55,8 +57,8 @@ bool nic_data_get(const char *id, struct nic_data *data_ptr)
else
goto out;
strncpy(data.owner, argv[11], sizeof(data.owner));
strncpy(data.name, argv[12], sizeof(data.name));
util_strlcpy(data.owner, argv[11], NIC_OWNER_SIZE);
util_strlcpy(data.name, argv[12], NIC_NAME_SIZE);
result = true;
*data_ptr = data;