mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2026-06-08 18:14:53 +00:00
dm: refine the check of return value of snprintf
int snprintf(char *str, size_t size, const char *format, ...)
The functions snprintf() write at most size bytes (including the
terminating null byte('\0')) to str.
only when returned value of snprintf is non-negative and less than size,
the string has been completely written.
Tracked-On: #3789
Signed-off-by: Junhao Gao <junhao.gao@intel.com>
Reviewed-by: Yonghua Huang <yonghua.huang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
This commit is contained in:
@@ -244,8 +244,8 @@ static int pci_npk_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
|
||||
/* read the host NPK configuration space */
|
||||
rc = snprintf(name, PATH_MAX, "%s/%s/config", NPK_DRV_SYSFS_PATH,
|
||||
dent->d_name);
|
||||
if (rc > PATH_MAX)
|
||||
WPRINTF(("NPK device name too long\n"));
|
||||
if (rc >= PATH_MAX || rc < 0)
|
||||
WPRINTF(("NPK device name is invalid!\n"));
|
||||
fd = open(name, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
WPRINTF(("Cannot open host NPK config\n"));
|
||||
|
||||
Reference in New Issue
Block a user