From fcad7de1a8c3d140d1d0eb120727966017d3727b Mon Sep 17 00:00:00 2001 From: Chris Leech Date: Sat, 17 Aug 2013 15:50:45 -0700 Subject: libiscsi: fix incorrect strncpy use Changes to internal structures make the src and dst buffers of some copies (potentially) different sizes. Fix strncpy calls that were using the size of the src argument as the limit. --- libiscsi/libiscsi.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/libiscsi/libiscsi.c b/libiscsi/libiscsi.c index 6e6846a..064e4b5 100644 --- a/libiscsi/libiscsi.c +++ b/libiscsi/libiscsi.c @@ -587,15 +587,13 @@ int libiscsi_get_firmware_network_config( return ENODEV; config->dhcp = strlen(fw_entry.dhcp) ? 1 : 0; - strncpy(config->iface_name, fw_entry.iface, sizeof fw_entry.iface); - strncpy(config->mac_address, fw_entry.mac, sizeof fw_entry.mac); - strncpy(config->ip_address, fw_entry.ipaddr, sizeof fw_entry.ipaddr); - strncpy(config->netmask, fw_entry.mask, sizeof fw_entry.mask); - strncpy(config->gateway, fw_entry.gateway, sizeof fw_entry.gateway); - strncpy(config->primary_dns, fw_entry.primary_dns, - sizeof fw_entry.primary_dns); - strncpy(config->secondary_dns, fw_entry.secondary_dns, - sizeof fw_entry.secondary_dns); + strlcpy(config->iface_name, fw_entry.iface, LIBISCSI_VALUE_MAXLEN); + strlcpy(config->mac_address, fw_entry.mac, LIBISCSI_VALUE_MAXLEN); + strlcpy(config->ip_address, fw_entry.ipaddr, LIBISCSI_VALUE_MAXLEN); + strlcpy(config->netmask, fw_entry.mask, LIBISCSI_VALUE_MAXLEN); + strlcpy(config->gateway, fw_entry.gateway, LIBISCSI_VALUE_MAXLEN); + strlcpy(config->primary_dns, fw_entry.primary_dns, LIBISCSI_VALUE_MAXLEN); + strlcpy(config->secondary_dns, fw_entry.secondary_dns, LIBISCSI_VALUE_MAXLEN); return 0; } @@ -613,8 +611,7 @@ int libiscsi_get_firmware_initiator_name(char *initiatorname) if (fw_get_entry(&fw_entry)) return ENODEV; - strncpy(initiatorname, fw_entry.initiatorname, - sizeof fw_entry.initiatorname); + strlcpy(initiatorname, fw_entry.initiatorname, LIBISCSI_VALUE_MAXLEN); return 0; } -- 1.8.1.4