From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:57827) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFphe-0005WW-So for qemu-devel@nongnu.org; Thu, 05 Apr 2012 12:38:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SFphY-00033v-1F for qemu-devel@nongnu.org; Thu, 05 Apr 2012 12:38:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32975) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SFphX-00033H-Nu for qemu-devel@nongnu.org; Thu, 05 Apr 2012 12:38:23 -0400 From: Kevin Wolf Date: Thu, 5 Apr 2012 17:51:47 +0200 Message-Id: <1333641144-13612-10-git-send-email-kwolf@redhat.com> In-Reply-To: <1333641144-13612-1-git-send-email-kwolf@redhat.com> References: <1333641144-13612-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 09/46] ide: Change serial number strncpy() to pstrcpy() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: Floris Bos strncpy may not null-terminate the destination string. Cc: kwolf@redhat.com Signed-off-by: Floris Bos Signed-off-by: Kevin Wolf --- blockdev.c | 5 +++-- hw/ide/core.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/blockdev.c b/blockdev.c index 1a500b8..f5e7dba 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 e38cace..5647694 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); -- 1.7.6.5