net/intel: fix use of non-recommended string functions
PATCH 1/1 net/intel: fix use of non-recommended string functions
Replace use of the strncpy and strcpy functions with the safer strlcpy alternative, which both bounds-checks and guarantees null termination. In the process also replace instances of strcat with strlcat where appropriate.
--- drivers/net/intel/cpfl/cpfl_ethdev.c | 2 +- drivers/net/intel/cpfl/cpfl_flow_parser.c | 16 +++++++--------- drivers/net/intel/e1000/igb_ethdev.c | 5 +++-- drivers/net/intel/i40e/i40e_ethdev.c | 3 +-- drivers/net/intel/ice/ice_ethdev.c | 16 +++++++--------- drivers/net/intel/idpf/idpf_ethdev.c | 2 +- drivers/net/intel/ixgbe/ixgbe_ethdev.c | 5 +++-- 7 files changed, 23 insertions(+), 26 deletions(-)
drivers/net/intel/cpfl/cpfl_ethdev.c +1 -1
@@ -2534,7 +2534,7 @@ cpfl_adapter_ext_init(struct rte_pci_device *pci_dev, struct cpfl_adapter_ext *a hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id; adapter->host_id =get_running_host_id (); -strncpy (adapter->name, pci_dev->device.name,PCI_PRI_STR_SIZE ); +strlcpy (adapter->name, pci_dev->device.name,sizeof (adapter->name));memcpy (&base->caps, &req_caps,sizeof (struct virtchnl2_get_capabilities ));
drivers/net/intel/cpfl/cpfl_flow_parser.c +7 -9
@@ -211,7 +211,7 @@ cpfl_flow_js_pattern_key_proto_field(json_t *ob_fields,PMD_DRV_LOG (ERR ,"The 'name' is too long." ); goto err; } -strncpy (js_field->fields[i].name, name,CPFL_JS_STR_SIZE -1 ); +strlcpy (js_field->fields[i].name, name,CPFL_JS_STR_SIZE );if (js_field->type ==RTE_FLOW_ITEM_TYPE_ETH || js_field->type ==RTE_FLOW_ITEM_TYPE_IPV4 ) {
@@ -716,8 +716,7 @@ cpfl_flow_js_mr_key(json_t *ob_mr_keys, struct cpfl_flow_js_mr_key *js_mr_key)PMD_DRV_LOG (ERR ,"The 'name' is too long." ); goto err; } -strncpy (js_mr_key->actions[i].prog.name, name, -CPFL_JS_STR_SIZE -1 ); +strlcpy (js_mr_key->actions[i].prog.name, name,CPFL_JS_STR_SIZE ); } ob_param =json_object_get (object,"parameters" );
@@ -742,8 +741,8 @@ cpfl_flow_js_mr_key(json_t *ob_mr_keys, struct cpfl_flow_js_mr_key *js_mr_key)PMD_DRV_LOG (ERR ,"The 'name' is too long." ); goto err; } -strncpy (js_mr_key->actions[i].prog.params[j].name, name, -CPFL_JS_STR_SIZE -1 ); +strlcpy (js_mr_key->actions[i].prog.params[j].name, name, +CPFL_JS_STR_SIZE ); } ret =cpfl_json_t_to_uint16 (subobject,"size" , &value);if (ret <0 ) {
@@ -810,7 +809,7 @@ cpfl_flow_js_mr_layout(json_t *ob_layouts, struct cpfl_flow_js_mr_action_mod *jsPMD_DRV_LOG (ERR ,"The 'hint' is too long." ); goto err; } -strncpy (js_mod->layout[i].hint, hint,CPFL_JS_STR_SIZE -1 ); +strlcpy (js_mod->layout[i].hint, hint,CPFL_JS_STR_SIZE ); }return 0 ;
@@ -856,7 +855,7 @@ cpfl_flow_js_mr_content(json_t *ob_content, struct cpfl_flow_js_mr_action_mod *jPMD_DRV_LOG (ERR ,"The 'type' is too long." ); goto err; } -strncpy (js_mod->content.fields[i].type, type,CPFL_JS_STR_SIZE -1 ); +strlcpy (js_mod->content.fields[i].type, type,CPFL_JS_STR_SIZE ); ret =cpfl_json_t_to_uint16 (object,"start" , &start);if (ret <0 ) {PMD_DRV_LOG (ERR ,"Can not parse 'start'." );
@@ -1806,8 +1805,7 @@ cpfl_parse_check_prog_action(struct cpfl_flow_js_mr_key_action *key_act,return -EINVAL ;if (param->has_name) { mr_key_prog->has_name = TRUE; -strncpy (mr_key_prog->name[param->index], param->name, -CPFL_JS_STR_SIZE -1 ); +strlcpy (mr_key_prog->name[param->index], param->name,CPFL_JS_STR_SIZE ); } }
drivers/net/intel/e1000/igb_ethdev.c +3 -2
@@ -2047,8 +2047,9 @@ static int eth_igb_xstats_get_names_by_id(struct rte_eth_dev *dev,PMD_INIT_LOG (ERR ,"id value isn't valid" );return -1 ; } -strcpy (xstats_names[i].name, - xstats_names_copy[ids[i]].name); +strlcpy (xstats_names[i].name, + xstats_names_copy[ids[i]].name, +sizeof (xstats_names[i].name)); }return limit; }
drivers/net/intel/i40e/i40e_ethdev.c +1 -2
@@ -11916,8 +11916,7 @@ i40e_update_customized_ptype(struct rte_eth_dev *dev, uint8_t *pkg,for (n =0 ; n < proto_num; n++) {if (proto[n].proto_id != proto_id)continue ; -memset (name,0 ,sizeof (name)); -strcpy (name, proto[n].name); +strlcpy (name, proto[n].name,sizeof (name));PMD_DRV_LOG (INFO ,"name = %s" , name);if (!strncasecmp (name,"PPPOE" ,5 )) ptype_mapping[i].sw_ptype |=
drivers/net/intel/ice/ice_ethdev.c +7 -9
@@ -1897,7 +1897,7 @@ ice_send_driver_ver(struct ice_hw *hw) dv.minor_ver =0 ; dv.build_ver =0 ; dv.subbuild_ver =0 ; -strncpy ((char *)dv.driver_string,"dpdk" ,sizeof (dv.driver_string)); +strlcpy ((char *)dv.driver_string,"dpdk" ,sizeof (dv.driver_string));return ice_aq_send_driver_ver (hw, &dv,NULL ); }
@@ -2054,24 +2054,22 @@ int ice_load_pkg(struct ice_adapter *adapter, bool use_dsn, uint64_t dsn)if (!use_dsn) goto no_dsn; -strncpy (pkg_file,ICE_PKG_FILE_SEARCH_PATH_UPDATES , -ICE_MAX_PKG_FILENAME_SIZE ); -strcat (pkg_file, opt_ddp_filename); +strlcpy (pkg_file,ICE_PKG_FILE_SEARCH_PATH_UPDATES ,ICE_MAX_PKG_FILENAME_SIZE ); +strlcat (pkg_file, opt_ddp_filename,ICE_MAX_PKG_FILENAME_SIZE );if (ice_firmware_read (pkg_file, &buf, &bufsz) ==0 ) goto load_fw; -strncpy (pkg_file,ICE_PKG_FILE_SEARCH_PATH_DEFAULT , -ICE_MAX_PKG_FILENAME_SIZE ); -strcat (pkg_file, opt_ddp_filename); +strlcpy (pkg_file,ICE_PKG_FILE_SEARCH_PATH_DEFAULT ,ICE_MAX_PKG_FILENAME_SIZE ); +strlcat (pkg_file, opt_ddp_filename,ICE_MAX_PKG_FILENAME_SIZE );if (ice_firmware_read (pkg_file, &buf, &bufsz) ==0 ) goto load_fw; no_dsn: -strncpy (pkg_file,ICE_PKG_FILE_UPDATES ,ICE_MAX_PKG_FILENAME_SIZE ); +strlcpy (pkg_file,ICE_PKG_FILE_UPDATES ,ICE_MAX_PKG_FILENAME_SIZE );if (ice_firmware_read (pkg_file, &buf, &bufsz) ==0 ) goto load_fw; -strncpy (pkg_file,ICE_PKG_FILE_DEFAULT ,ICE_MAX_PKG_FILENAME_SIZE ); +strlcpy (pkg_file,ICE_PKG_FILE_DEFAULT ,ICE_MAX_PKG_FILENAME_SIZE );if (ice_firmware_read (pkg_file, &buf, &bufsz) <0 ) {PMD_INIT_LOG (ERR ,"Failed to load default DDP package " ICE_PKG_FILE_DEFAULT );return -1 ;
drivers/net/intel/idpf/idpf_ethdev.c +1 -1
@@ -1497,7 +1497,7 @@ idpf_adapter_ext_init(struct rte_pci_device *pci_dev, struct idpf_adapter_ext *a hw->device_id = pci_dev->id.device_id; hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id; -strncpy (adapter->name, pci_dev->device.name,PCI_PRI_STR_SIZE ); +strlcpy (adapter->name, pci_dev->device.name,sizeof (adapter->name));memcpy (&base->caps, &req_caps,sizeof (struct virtchnl2_get_capabilities ));
drivers/net/intel/ixgbe/ixgbe_ethdev.c +3 -2
@@ -3635,8 +3635,9 @@ static int ixgbe_dev_xstats_get_names_by_id(PMD_INIT_LOG (ERR ,"id value isn't valid" );return -1 ; } -strcpy (xstats_names[i].name, - xstats_names_copy[ids[i]].name); +strlcpy (xstats_names[i].name, + xstats_names_copy[ids[i]].name, +sizeof (xstats_names[i].name)); }return limit; }
Signature · 1 line
2.53.0
Quoted 18 lines
Subject: [PATCH] net/intel: fix use of non-recommended string functions
Replace use of the strncpy and strcpy functions with the safer strlcpy alternative, which both bounds-checks and guarantees null termination. In the process also replace instances of strcat with strlcat where appropriate.
Fixes 2d823ecd671c ("net/cpfl: support device initialization")Fixes c4c59ae62793 ("net/cpfl: refactor flow parser")Fixes c10881d3ee74 ("net/cpfl: support flow prog action")Fixes 9481b0902efe ("net/ice: send driver version to firmware")Fixes 7f7cbf80bdb7 ("net/ice: factorize firmware loading")Fixes 549343c25db8 ("net/idpf: support device initialization")Fixes 484f8e407a94 ("net/igb: support xstats by ID")Fixes fca82a8accf9 ("net/ixgbe: support xstats by ID")Fixes e163c18a15b0 ("net/i40e: update ptype and pctype info")
Quoted 1 line
Signed-off-by Bruce Richardson <[email protected]>
Quoted 10 lines
--- drivers/net/intel/cpfl/cpfl_ethdev.c | 2 +- drivers/net/intel/cpfl/cpfl_flow_parser.c | 16 +++++++--------- drivers/net/intel/e1000/igb_ethdev.c | 5 +++-- drivers/net/intel/i40e/i40e_ethdev.c | 3 +-- drivers/net/intel/ice/ice_ethdev.c | 16 +++++++--------- drivers/net/intel/idpf/idpf_ethdev.c | 2 +- drivers/net/intel/ixgbe/ixgbe_ethdev.c | 5 +++-- 7 files changed, 23 insertions(+), 26 deletions(-)
Bruce Richardson
AppliedQuoted 18 lines · Ciara
Quoted 18 lines
Subject: [PATCH] net/intel: fix use of non-recommended string functions
Replace use of the strncpy and strcpy functions with the safer strlcpy alternative, which both bounds-checks and guarantees null termination. In the process also replace instances of strcat with strlcat where appropriate.
Fixes 2d823ecd671c ("net/cpfl: support device initialization")Fixes c4c59ae62793 ("net/cpfl: refactor flow parser")Fixes c10881d3ee74 ("net/cpfl: support flow prog action")Fixes 9481b0902efe ("net/ice: send driver version to firmware")Fixes 7f7cbf80bdb7 ("net/ice: factorize firmware loading")Fixes 549343c25db8 ("net/idpf: support device initialization")Fixes 484f8e407a94 ("net/igb: support xstats by ID")Fixes fca82a8accf9 ("net/ixgbe: support xstats by ID")Fixes e163c18a15b0 ("net/i40e: update ptype and pctype info")
Quoted 4 lines
Quoted 1 line
Signed-off-by Bruce Richardson <[email protected]>Acked-by Ciara Loftus <[email protected]>
Applied to dpdk-next-net-intel.
/Bruce