]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
i40e: Replace strncpy with strlcpy to ensure null termination
authorPatryk Małek <patryk.malek@intel.com>
Tue, 30 Oct 2018 17:50:44 +0000 (10:50 -0700)
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>
Wed, 14 Nov 2018 18:56:33 +0000 (10:56 -0800)
Using strncpy allows destination buffer to be not null terminated
after the copying takes place. strlcpy ensures that's not the
case by explicitly setting last element in the buffer as '\0'.

Signed-off-by: Patryk Małek <patryk.malek@intel.com>
Tested-by: Andrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
drivers/net/ethernet/intel/i40e/i40e_main.c
drivers/net/ethernet/intel/i40e/i40e_ptp.c

index 7e4c07227832da6cdd838e3d5a8653cf264d9ef2..b6f4ebb4557ec5181c6662bba1ed15703d962d80 100644 (file)
@@ -14301,23 +14301,23 @@ static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 
                switch (hw->bus.speed) {
                case i40e_bus_speed_8000:
-                       strncpy(speed, "8.0", PCI_SPEED_SIZE); break;
+                       strlcpy(speed, "8.0", PCI_SPEED_SIZE); break;
                case i40e_bus_speed_5000:
-                       strncpy(speed, "5.0", PCI_SPEED_SIZE); break;
+                       strlcpy(speed, "5.0", PCI_SPEED_SIZE); break;
                case i40e_bus_speed_2500:
-                       strncpy(speed, "2.5", PCI_SPEED_SIZE); break;
+                       strlcpy(speed, "2.5", PCI_SPEED_SIZE); break;
                default:
                        break;
                }
                switch (hw->bus.width) {
                case i40e_bus_width_pcie_x8:
-                       strncpy(width, "8", PCI_WIDTH_SIZE); break;
+                       strlcpy(width, "8", PCI_WIDTH_SIZE); break;
                case i40e_bus_width_pcie_x4:
-                       strncpy(width, "4", PCI_WIDTH_SIZE); break;
+                       strlcpy(width, "4", PCI_WIDTH_SIZE); break;
                case i40e_bus_width_pcie_x2:
-                       strncpy(width, "2", PCI_WIDTH_SIZE); break;
+                       strlcpy(width, "2", PCI_WIDTH_SIZE); break;
                case i40e_bus_width_pcie_x1:
-                       strncpy(width, "1", PCI_WIDTH_SIZE); break;
+                       strlcpy(width, "1", PCI_WIDTH_SIZE); break;
                default:
                        break;
                }
index 1199f0502d6d5169fa211beb15f3b86331428582..e6fc0aff8c9956c2de65fb1158f649cf48513342 100644 (file)
@@ -694,7 +694,7 @@ static long i40e_ptp_create_clock(struct i40e_pf *pf)
        if (!IS_ERR_OR_NULL(pf->ptp_clock))
                return 0;
 
-       strncpy(pf->ptp_caps.name, i40e_driver_name,
+       strlcpy(pf->ptp_caps.name, i40e_driver_name,
                sizeof(pf->ptp_caps.name) - 1);
        pf->ptp_caps.owner = THIS_MODULE;
        pf->ptp_caps.max_adj = 999999999;