[dpdk-dev] bus/ifpga: fix strncpy with wrong length with strlcpy

Message ID 152618185248.125230.3244687143464768033.stgit@localhost.localdomain (mailing list archive)
State Rejected, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Andy Green May 13, 2018, 3:24 a.m. UTC
  In function ‘ifpga_scan_one’,
    inlined from ‘ifpga_scan’ at /home/agreen/projects/
lagopus/src/dpdk/drivers/bus/ifpga/ifpga_bus.c:229:13:
/home/agreen/projects/lagopus/src/dpdk/drivers/bus/ifpga/
ifpga_bus.c:161:2: error: ‘strncpy’ specified bound 256
equals destination size [-Werror=stringop-truncation]
  strncpy(afu_pr_conf.bs_path, path,
sizeof(afu_pr_conf.bs_path));
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~

Signed-off-by: Andy Green <andy@warmcat.com>
Fixes: 05fa3d4a65 ("bus/ifpga: add Intel FPGA bus library")
---
 drivers/bus/ifpga/ifpga_bus.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Andy Green May 13, 2018, 3:26 a.m. UTC | #1
On 05/13/2018 11:24 AM, Andy Green wrote:
> In function ‘ifpga_scan_one’,
>      inlined from ‘ifpga_scan’ at /home/agreen/projects/
> lagopus/src/dpdk/drivers/bus/ifpga/ifpga_bus.c:229:13:
> /home/agreen/projects/lagopus/src/dpdk/drivers/bus/ifpga/
> ifpga_bus.c:161:2: error: ‘strncpy’ specified bound 256
> equals destination size [-Werror=stringop-truncation]
>    strncpy(afu_pr_conf.bs_path, path,
> sizeof(afu_pr_conf.bs_path));
>    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ~~~~~~~~~~~~
> 
> Signed-off-by: Andy Green <andy@warmcat.com>
> Fixes: 05fa3d4a65 ("bus/ifpga: add Intel FPGA bus library")
> ---
>   drivers/bus/ifpga/ifpga_bus.c |    3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/bus/ifpga/ifpga_bus.c b/drivers/bus/ifpga/ifpga_bus.c
> index 16b7e06b6..08b3c8fdd 100644
> --- a/drivers/bus/ifpga/ifpga_bus.c
> +++ b/drivers/bus/ifpga/ifpga_bus.c
> @@ -20,6 +20,7 @@
>   #include <rte_memzone.h>
>   #include <rte_eal.h>
>   #include <rte_common.h>
> +#include <rte_string_fns.h>
>   
>   #include <rte_devargs.h>
>   #include <rte_kvargs.h>
> @@ -158,7 +159,7 @@ ifpga_scan_one(struct rte_rawdev *rawdev,
>   		rawdev->dev_ops->dev_start(rawdev))
>   		goto free_dev;
>   
> -	strncpy(afu_pr_conf.bs_path, path, sizeof(afu_pr_conf.bs_path));
> +	strlcpy(afu_pr_conf.bs_path, path, sizeof(afu_pr_conf.bs_path));
>   	if (rawdev->dev_ops->firmware_load &&
>   		rawdev->dev_ops->firmware_load(rawdev,
>   				&afu_pr_conf)){
> 

Never mind... I just saw Pablo's patch from yesterday when checking this 
went through, ignore this one.
  

Patch

diff --git a/drivers/bus/ifpga/ifpga_bus.c b/drivers/bus/ifpga/ifpga_bus.c
index 16b7e06b6..08b3c8fdd 100644
--- a/drivers/bus/ifpga/ifpga_bus.c
+++ b/drivers/bus/ifpga/ifpga_bus.c
@@ -20,6 +20,7 @@ 
 #include <rte_memzone.h>
 #include <rte_eal.h>
 #include <rte_common.h>
+#include <rte_string_fns.h>
 
 #include <rte_devargs.h>
 #include <rte_kvargs.h>
@@ -158,7 +159,7 @@  ifpga_scan_one(struct rte_rawdev *rawdev,
 		rawdev->dev_ops->dev_start(rawdev))
 		goto free_dev;
 
-	strncpy(afu_pr_conf.bs_path, path, sizeof(afu_pr_conf.bs_path));
+	strlcpy(afu_pr_conf.bs_path, path, sizeof(afu_pr_conf.bs_path));
 	if (rawdev->dev_ops->firmware_load &&
 		rawdev->dev_ops->firmware_load(rawdev,
 				&afu_pr_conf)){