readlink() does not terminate string, add a null character at the end
of the string if readlink() succeeds.
Coverity issue: 362820
Fixes:
9c006c45d0c5 ("raw/ifpga: scan PCIe BDF device tree")
Cc: stable@dpdk.org
Signed-off-by: Wei Huang <wei.huang@intel.com>
Acked-by: Qi Zhang <qi.z.zhang@intel.com>
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);