Fix string may be truncated issue with using snprintf

New compiler options introduced by commit
519c4285cf will cause DM compile failure
which caused by warnings from some snprintf usage might be truncated.

Expanding the string buffer to make compiler happy.

v3: change format string
v2: Address comment from Hao, shrink bident string size to satify
tname length in blockif_open.

Signed-off-by: Rusty Lynch <rusty.lynch@intel.com>
Signed-off-by: Liu Shuo <shuo.a.liu@intel.com>
This commit is contained in:
Liu Shuo 2018-03-21 17:44:02 +08:00 committed by lijinxia
parent 383bc5100a
commit 4c96a58601
2 changed files with 5 additions and 4 deletions

View File

@ -2312,10 +2312,11 @@ pci_ahci_read(struct vmctx *ctx, int vcpu, struct pci_vdev *dev, int baridx,
static int static int
pci_ahci_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts, int atapi) pci_ahci_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts, int atapi)
{ {
char bident[sizeof("XX:XX:XX")]; char bident[16];
struct blockif_ctxt *bctxt; struct blockif_ctxt *bctxt;
struct pci_ahci_vdev *ahci_dev; struct pci_ahci_vdev *ahci_dev;
int ret, slots, p; int ret, slots;
uint8_t p;
MD5_CTX mdctx; MD5_CTX mdctx;
u_char digest[16]; u_char digest[16];
char *next, *next2; char *next, *next2;
@ -2365,7 +2366,7 @@ pci_ahci_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts, int atapi)
* Attempt to open the backing image. Use the PCI slot/func * Attempt to open the backing image. Use the PCI slot/func
* and the port number for the identifier string. * and the port number for the identifier string.
*/ */
snprintf(bident, sizeof(bident), "%d:%d:%d", dev->slot, snprintf(bident, sizeof(bident), "%02x:%02x:%02x", dev->slot,
dev->func, p); dev->func, p);
bctxt = blockif_open(opts, bident); bctxt = blockif_open(opts, bident);
if (bctxt == NULL) { if (bctxt == NULL) {

View File

@ -285,7 +285,7 @@ virtio_blk_notify(void *vdev, struct virtio_vq_info *vq)
static int static int
virtio_blk_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts) virtio_blk_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
{ {
char bident[sizeof("XX:X:X")]; char bident[16];
struct blockif_ctxt *bctxt; struct blockif_ctxt *bctxt;
MD5_CTX mdctx; MD5_CTX mdctx;
u_char digest[16]; u_char digest[16];