Skip to content

Commit

Permalink
raw/ifpga: terminate string filled by readlink with null
Browse files Browse the repository at this point in the history
[ upstream commit 5a90690 ]

readlink() does not terminate string, add a null character at the end
of the string if readlink() succeeds.

Coverity issue: 362820
Fixes: 9c006c4 ("raw/ifpga: scan PCIe BDF device tree")

Signed-off-by: Wei Huang <wei.huang@intel.com>
Acked-by: Qi Zhang <qi.z.zhang@intel.com>
  • Loading branch information
weihuan2 authored and bluca committed Nov 9, 2020
1 parent 060f174 commit 6bf53dd
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/raw/ifpga/ifpga_rawdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,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);
Expand Down

0 comments on commit 6bf53dd

Please sign in to comment.