diff mbox series

[v2,1/2] raw/ifpga: terminate string filled by readlink with null

Message ID 1604017294-23479-2-git-send-email-wei.huang@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Qi Zhang
Headers show
Series raw/ifpga: fix coverity defects | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Wei Huang Oct. 30, 2020, 12:21 a.m. UTC
readlink() does not terminate string, add a null character at the end
of the string if readlink() succeeds.

Fixes: 9c006c45d0c5 ("raw/ifpga: scan PCIe BDF device tree")

Signed-off-by: Wei Huang <wei.huang@intel.com>
---
v2: fix coding style issue
---
 drivers/raw/ifpga/ifpga_rawdev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Zhang, Tianfei Oct. 30, 2020, 6:56 a.m. UTC | #1
> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Wei Huang
> Sent: 2020年10月30日 8:22
> To: dev@dpdk.org; Xu, Rosen <rosen.xu@intel.com>; Zhang, Qi Z
> <qi.z.zhang@intel.com>
> Cc: Huang, Wei <wei.huang@intel.com>
> Subject: [dpdk-dev] [PATCH v2 1/2] raw/ifpga: terminate string filled by
> readlink with null
> 
> readlink() does not terminate string, add a null character at the end of the
> string if readlink() succeeds.
> 
> Fixes: 9c006c45d0c5 ("raw/ifpga: scan PCIe BDF device tree")

It is better add Coverity issue number , like "Coverity issue: xxxx ".
Missing “Cc: stable@dpdk.org”

> 
> Signed-off-by: Wei Huang <wei.huang@intel.com>
> ---
> v2: fix coding style issue
> ---
>  drivers/raw/ifpga/ifpga_rawdev.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/raw/ifpga/ifpga_rawdev.c
> b/drivers/raw/ifpga/ifpga_rawdev.c
> index 0385514..f9de167 100644
> --- a/drivers/raw/ifpga/ifpga_rawdev.c
> +++ b/drivers/raw/ifpga/ifpga_rawdev.c
> @@ -230,8 +230,9 @@ static int ifpga_rawdev_fill_info(struct ifpga_rawdev
> *ifpga_dev,
>  	memset(link, 0, sizeof(link));
>  	memset(link1, 0, sizeof(link1));
>  	ret = readlink(path, link, (sizeof(link)-1));
> -	if (ret == -1)
> +	if ((ret < 0) || ((unsigned int)ret > (sizeof(link)-1)))
>  		return -1;
> +	link[ret] = 0;   /* terminate string with null character */

link[ret] = '\0';

>  	strlcpy(link1, link, sizeof(link1));
>  	memset(ifpga_dev->parent_bdf, 0, 16);
>  	point = strlen(link);
> --
> 2.7.3
diff mbox series

Patch

diff --git a/drivers/raw/ifpga/ifpga_rawdev.c b/drivers/raw/ifpga/ifpga_rawdev.c
index 0385514..f9de167 100644
--- a/drivers/raw/ifpga/ifpga_rawdev.c
+++ b/drivers/raw/ifpga/ifpga_rawdev.c
@@ -230,8 +230,9 @@  static int ifpga_rawdev_fill_info(struct ifpga_rawdev *ifpga_dev,
 	memset(link, 0, sizeof(link));
 	memset(link1, 0, sizeof(link1));
 	ret = readlink(path, link, (sizeof(link)-1));
-	if (ret == -1)
+	if ((ret < 0) || ((unsigned int)ret > (sizeof(link)-1)))
 		return -1;
+	link[ret] = 0;   /* terminate string with null character */
 	strlcpy(link1, link, sizeof(link1));
 	memset(ifpga_dev->parent_bdf, 0, 16);
 	point = strlen(link);