igb: Fix strncpy calls to be safe per source code review tools
authorCarolyn Wyborny <carolyn.wyborny@intel.com>
Wed, 2 Mar 2011 01:11:26 +0000 (01:11 +0000)
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>
Thu, 3 Mar 2011 10:48:32 +0000 (02:48 -0800)
This fix changes the remaining calls to strncpy that have not yet
been changed to use the "sizeof(buf) - 1" syntax rather than just
a number for buffer size.

Signed-off-by: Carolyn Wyborny <carolyn.wyborny@intel.com>
Tested-by: Aaron Brown <aaron.f.brown@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
drivers/net/igb/igb_ethtool.c

index 16bbd4922bc3ec5c55e7d0af4b211f239c7b62dd..61f7849cb5a70b1223ec7c88c5aa80e02fcf56fe 100644 (file)
@@ -727,8 +727,9 @@ static void igb_get_drvinfo(struct net_device *netdev,
        char firmware_version[32];
        u16 eeprom_data;
 
-       strncpy(drvinfo->driver,  igb_driver_name, 32);
-       strncpy(drvinfo->version, igb_driver_version, 32);
+       strncpy(drvinfo->driver,  igb_driver_name, sizeof(drvinfo->driver) - 1);
+       strncpy(drvinfo->version, igb_driver_version,
+               sizeof(drvinfo->version) - 1);
 
        /* EEPROM image version # is reported as firmware version # for
         * 82575 controllers */
@@ -738,8 +739,10 @@ static void igb_get_drvinfo(struct net_device *netdev,
                (eeprom_data & 0x0FF0) >> 4,
                eeprom_data & 0x000F);
 
-       strncpy(drvinfo->fw_version, firmware_version, 32);
-       strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
+       strncpy(drvinfo->fw_version, firmware_version,
+               sizeof(drvinfo->fw_version) - 1);
+       strncpy(drvinfo->bus_info, pci_name(adapter->pdev),
+               sizeof(drvinfo->bus_info) - 1);
        drvinfo->n_stats = IGB_STATS_LEN;
        drvinfo->testinfo_len = IGB_TEST_LEN;
        drvinfo->regdump_len = igb_get_regs_len(netdev);