Skip to content

Commit 544ec38

Browse files
Liu Shuojren1
authored andcommitted
Fix string may be truncated issue with using snprintf
New compiler options introduced by commit 519c428 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>
1 parent 2205d5e commit 544ec38

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

devicemodel/hw/pci/ahci.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2312,10 +2312,11 @@ pci_ahci_read(struct vmctx *ctx, int vcpu, struct pci_vdev *dev, int baridx,
23122312
static int
23132313
pci_ahci_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts, int atapi)
23142314
{
2315-
char bident[sizeof("XX:XX:XX")];
2315+
char bident[16];
23162316
struct blockif_ctxt *bctxt;
23172317
struct pci_ahci_vdev *ahci_dev;
2318-
int ret, slots, p;
2318+
int ret, slots;
2319+
uint8_t p;
23192320
MD5_CTX mdctx;
23202321
u_char digest[16];
23212322
char *next, *next2;
@@ -2365,7 +2366,7 @@ pci_ahci_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts, int atapi)
23652366
* Attempt to open the backing image. Use the PCI slot/func
23662367
* and the port number for the identifier string.
23672368
*/
2368-
snprintf(bident, sizeof(bident), "%d:%d:%d", dev->slot,
2369+
snprintf(bident, sizeof(bident), "%02x:%02x:%02x", dev->slot,
23692370
dev->func, p);
23702371
bctxt = blockif_open(opts, bident);
23712372
if (bctxt == NULL) {

devicemodel/hw/pci/virtio/virtio_block.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ virtio_blk_notify(void *vdev, struct virtio_vq_info *vq)
285285
static int
286286
virtio_blk_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
287287
{
288-
char bident[sizeof("XX:X:X")];
288+
char bident[16];
289289
struct blockif_ctxt *bctxt;
290290
MD5_CTX mdctx;
291291
u_char digest[16];

0 commit comments

Comments
 (0)