From 4c96a58601285a83ebe603157676bff5cf851023 Mon Sep 17 00:00:00 2001 From: Liu Shuo Date: Wed, 21 Mar 2018 17:44:02 +0800 Subject: [PATCH] Fix string may be truncated issue with using snprintf New compiler options introduced by commit 519c4285cf104a594776591075ee1c6ee4d61815 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 Signed-off-by: Liu Shuo --- hw/pci/ahci.c | 7 ++++--- hw/pci/virtio/virtio_block.c | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/hw/pci/ahci.c b/hw/pci/ahci.c index bc92efd5d..0fa942274 100644 --- a/hw/pci/ahci.c +++ b/hw/pci/ahci.c @@ -2312,10 +2312,11 @@ pci_ahci_read(struct vmctx *ctx, int vcpu, struct pci_vdev *dev, int baridx, static int 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 pci_ahci_vdev *ahci_dev; - int ret, slots, p; + int ret, slots; + uint8_t p; MD5_CTX mdctx; u_char digest[16]; 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 * 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); bctxt = blockif_open(opts, bident); if (bctxt == NULL) { diff --git a/hw/pci/virtio/virtio_block.c b/hw/pci/virtio/virtio_block.c index e4a3dd78b..810967fd0 100644 --- a/hw/pci/virtio/virtio_block.c +++ b/hw/pci/virtio/virtio_block.c @@ -285,7 +285,7 @@ virtio_blk_notify(void *vdev, struct virtio_vq_info *vq) static int 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; MD5_CTX mdctx; u_char digest[16];