From: Floris Bos Date: Mon, 12 Mar 2012 20:05:10 +0000 (+0100) Subject: ide: Change serial number strncpy() to pstrcpy() X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=aa2c91bdfebbfa314e9522573a9656626e21ac67;p=qemu.git ide: Change serial number strncpy() to pstrcpy() strncpy may not null-terminate the destination string. Cc: kwolf@redhat.com Signed-off-by: Floris Bos Signed-off-by: Kevin Wolf --- diff --git a/blockdev.c b/blockdev.c index 1a500b830d..f5e7dba90c 100644 --- a/blockdev.c +++ b/blockdev.c @@ -532,8 +532,9 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi) dinfo->unit = unit_id; dinfo->opts = opts; dinfo->refcount = 1; - if (serial) - strncpy(dinfo->serial, serial, sizeof(dinfo->serial) - 1); + if (serial) { + pstrcpy(dinfo->serial, sizeof(dinfo->serial), serial); + } QTAILQ_INSERT_TAIL(&drives, dinfo, next); bdrv_set_on_error(dinfo->bdrv, on_read_error, on_write_error); diff --git a/hw/ide/core.c b/hw/ide/core.c index e38cace45b..5647694585 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -1879,7 +1879,7 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind, } } if (serial) { - strncpy(s->drive_serial_str, serial, sizeof(s->drive_serial_str)); + pstrcpy(s->drive_serial_str, sizeof(s->drive_serial_str), serial); } else { snprintf(s->drive_serial_str, sizeof(s->drive_serial_str), "QM%05d", s->drive_serial);