> -----Original Message-----
> From: Huang, Wei <wei.hu...@intel.com>
> Sent: 2021年3月17日 16:22
> To: dev@dpdk.org; Xu, Rosen <rosen...@intel.com>; Zhang, Qi Z
> <qi.z.zh...@intel.com>
> Cc: sta...@dpdk.org; Zhang, Tianfei <tianfei.zh...@intel.com>; Huang, Wei
> <wei.hu...@intel.com>
> Subject: [PATCH v1 3/4] raw/ifpga/base: assign unsigned value to length
> 
> In fpga_update_flash(), "smgr->rsu_length" is passed to a parameter that
> cannot be negative. So return value of function "lseek" should be checked
> before being assigned to "smgr->rsu_length".
> 
> Coverity issue: 367481
> Fixes: 7a4f3993f269 ("raw/ifpga: add FPGA RSU APIs")
> 
> Signed-off-by: Wei Huang <wei.hu...@intel.com>
> ---
>  drivers/raw/ifpga/base/ifpga_fme_rsu.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/raw/ifpga/base/ifpga_fme_rsu.c
> b/drivers/raw/ifpga/base/ifpga_fme_rsu.c
> index a4cb2f54ba..79ee37c282 100644
> --- a/drivers/raw/ifpga/base/ifpga_fme_rsu.c
> +++ b/drivers/raw/ifpga/base/ifpga_fme_rsu.c
> @@ -277,6 +277,7 @@ int fpga_update_flash(struct ifpga_fme_hw *fme,
> const char *image,
>       struct ifpga_sec_mgr *smgr = NULL;
>       uint32_t rsu_stat = 0;
>       int fd = -1;
> +     off_t len = 0;
>       struct sigaction old_sigint_action;
>       struct sigaction sa;
>       time_t start;
> @@ -320,9 +321,21 @@ int fpga_update_flash(struct ifpga_fme_hw *fme,
> const char *image,
>                       image, strerror(errno));
>               return -EIO;
>       }
> -     smgr->rsu_length = lseek(fd, 0, SEEK_END);
> +     len = lseek(fd, 0, SEEK_END);
>       close(fd);
> 
> +     if (len < 0) {
> +             dev_err(smgr,
> +                     "Failed to get file length of \'%s\' [e:%s]\n",
> +                     image, strerror(errno));
> +             return -EIO;
> +     }
> +     if (len == 0) {
> +             dev_err(smgr, "Length of file \'%s\' is invalid\n", image);
> +             return -EINVAL;
> +     }
> +     smgr->rsu_length = len;
> +
>       if (smgr->max10_dev->staging_area_size < smgr->rsu_length) {
>               dev_err(dev, "Size of staging area is small than image length "
>                       "[%u<%u]\n", smgr->max10_dev->staging_area_size,
> --

Acked-by: Tianfei zhang <tianfei.zh...@intel.com>

Reply via email to