dm: hw: Replace sprintf with snprintf
Replace function sprintf with snprintf in device model Tracked-On: #2079 Signed-off-by: Long Liu <long.liu@intel.com> Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com> Reviewed-by: <yonghua.huang@intel.com> Acked-by: Yu Wang <yu1.wang@intel.com>
This commit is contained in:
parent
69dc939243
commit
eab7cd47ae
|
@ -2307,7 +2307,7 @@ pci_ahci_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts, int atapi)
|
|||
char bident[16];
|
||||
struct blockif_ctxt *bctxt;
|
||||
struct pci_ahci_vdev *ahci_dev;
|
||||
int ret, slots;
|
||||
int ret, slots, rc;
|
||||
uint8_t p;
|
||||
MD5_CTX mdctx;
|
||||
u_char digest[16];
|
||||
|
@ -2378,9 +2378,12 @@ pci_ahci_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts, int atapi)
|
|||
MD5_Init(&mdctx);
|
||||
MD5_Update(&mdctx, opts, strlen(opts));
|
||||
MD5_Final(digest, &mdctx);
|
||||
sprintf(ahci_dev->port[p].ident,
|
||||
rc = snprintf(ahci_dev->port[p].ident,
|
||||
sizeof(ahci_dev->port[p].ident),
|
||||
"ACRN--%02X%02X-%02X%02X-%02X%02X", digest[0],
|
||||
digest[1], digest[2], digest[3], digest[4], digest[5]);
|
||||
if (rc > sizeof(ahci_dev->port[p].ident))
|
||||
WPRINTF("%s: digest is longer than ident\n", __func__);
|
||||
|
||||
/*
|
||||
* Allocate blockif request structures and add them
|
||||
|
|
|
@ -178,7 +178,7 @@ static inline int valid_param(uint32_t m_off, uint32_t m_num)
|
|||
*/
|
||||
static int pci_npk_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
|
||||
{
|
||||
int i, b, s, f, fd, ret, error = -1;
|
||||
int i, b, s, f, fd, ret, rc, error = -1;
|
||||
DIR *dir;
|
||||
struct dirent *dent;
|
||||
char name[PATH_MAX];
|
||||
|
@ -239,7 +239,10 @@ static int pci_npk_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
|
|||
}
|
||||
|
||||
/* read the host NPK configuration space */
|
||||
sprintf(name, "%s/%s/config", NPK_DRV_SYSFS_PATH, dent->d_name);
|
||||
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"));
|
||||
fd = open(name, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
WPRINTF(("Cannot open host NPK config\n"));
|
||||
|
|
Loading…
Reference in New Issue