raw/ifpga: fix coverity defects
v2 cover raw/ifpga: fix coverity defects
These two patches fix defects found by coverity scan.
Main changes from v3:
- Add coverity issue number
Main changes from v2:
- Fix coding style issue
Wei Huang (2):
raw/ifpga: terminate string filled by readlink with null raw/ifpga: use trusted buffer to free
drivers/raw/ifpga/ifpga_rawdev.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
Signature · 1 line
2.7.3
PATCH v3 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.
Coverity issue: 362820
---
v2: fix coding style issue
v3: add coverity issue number
--- drivers/raw/ifpga/ifpga_rawdev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/raw/ifpga/ifpga_rawdev.c +2 -1
@@ -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);
Signature · 1 line
2.7.3
PATCH v3 2/2 raw/ifpga: use trusted buffer to free
In reply to Wei HuangIn rte_fpga_do_pr, calling function read() may taints argument buffer which turn to an untrusted value as argumen of rte_free().
Coverity issue: 279449
---
v2: add fixes information to log
v3: add coverity issue number
--- drivers/raw/ifpga/ifpga_rawdev.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/raw/ifpga/ifpga_rawdev.c +4 -3
@@ -786,7 +786,7 @@ rte_fpga_do_pr(struct rte_rawdev *rawdev, int port_id,int file_fd;int ret =0 ;ssize_t buffer_size; -void *buffer; +void *buffer, *buf_to_free;u64 pr_error;if (!file_name)
@@ -818,6 +818,7 @@ rte_fpga_do_pr(struct rte_rawdev *rawdev, int port_id, ret = -ENOMEM ; goto close_fd; } + buf_to_free = buffer;/*read the raw data*/ if (buffer_size !=read (file_fd, (void *)buffer, buffer_size)) {
@@ -835,8 +836,8 @@ rte_fpga_do_pr(struct rte_rawdev *rawdev, int port_id, } free_buffer: -if (buffer) -rte_free (buffer); +if (buf_to_free) +rte_free (buf_to_free); close_fd:close (file_fd); file_fd =0 ;
Signature · 1 line
2.7.3