Skip to contentSkip to conversation

block: Fix serial number assignment

PATCH Applied Luiz Capitulino 3 participants 3 messages Jun 2, 2010 – Jun 4, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: Fix serial number assignment

We should use 'dinfo->serial' length, 'serial' is a pointer, so the serial number length is currently limited to the pointer size.

This fixes https://bugs.launchpad.net/qemu/+bug/584143 and is also valid for stable.

---
 vl.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
vl.c +1 -1
index 417554f..3de2166 100644
@@ -1060,7 +1060,7 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque,
     dinfo->on_write_error = on_write_error;
     dinfo->opts = opts;
     if (serial)
-        strncpy(dinfo->serial, serial, sizeof(serial));
+        strncpy(dinfo->serial, serial, sizeof(dinfo->serial) - 1);
     QTAILQ_INSERT_TAIL(&drives, dinfo, next);
 
     switch(type) {
Signature · 1 line
1.7.1.231.gd0b16
#1 lore raw
Quoted 16 lines · Luiz Capitulino

We should use 'dinfo->serial' length, 'serial' is a pointer, so the serial number length is currently limited to the pointer size.

This fixes https://bugs.launchpad.net/qemu/+bug/584143 and is also valid for stable.

---
 vl.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
vl.c +0 -0
index 417554f..3de2166 100644

vl.c DriveInfo *drive_init(QemuOpts *opts, void *opaque, · line 1066

Quoted 8 lines
vl.c +1 -1
@@ -1060,7 +1060,7 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque,
     dinfo->on_write_error = on_write_error;
     dinfo->opts = opts;
     if (serial)
-        strncpy(dinfo->serial, serial, sizeof(serial));
+        strncpy(dinfo->serial, serial, sizeof(dinfo->serial) - 1);
     QTAILQ_INSERT_TAIL(&drives, dinfo, next);
 
     switch(type) {

Correct, because dinfo->serial[] is zero-initialized.

Patch conflicts with my "blockdev: Collect block device code in new blockdev.c", but resolution is trivial.