qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 2/4] Add virtio disk identification support
@ 2010-03-25  5:33 john cooper
  2010-06-03 19:10 ` [Qemu-devel] " Anthony Liguori
  0 siblings, 1 reply; 3+ messages in thread
From: john cooper @ 2010-03-25  5:33 UTC (permalink / raw)
  To: qemu-devel; +Cc: john.cooper, Rusty Russell, Marc Haber

Fix bug which truncated serial string to 8 bytes, nul terminate.

Signed-off-by: john cooper <john.cooper@redhat.com>
---

diff --git a/vl.c b/vl.c
index d69250c..b74cbba 100644
--- a/vl.c
+++ b/vl.c
@@ -1162,7 +1162,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) {

-- 
john.cooper@redhat.com

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [Qemu-devel] Re: [PATCH 2/4] Add virtio disk identification support
  2010-03-25  5:33 [Qemu-devel] [PATCH 2/4] Add virtio disk identification support john cooper
@ 2010-06-03 19:10 ` Anthony Liguori
  2010-06-04  6:34   ` john cooper
  0 siblings, 1 reply; 3+ messages in thread
From: Anthony Liguori @ 2010-06-03 19:10 UTC (permalink / raw)
  To: john cooper; +Cc: Rusty Russell, Marc Haber, qemu-devel

On 03/25/2010 12:33 AM, john cooper wrote:
> Fix bug which truncated serial string to 8 bytes, nul terminate.
>
> Signed-off-by: john cooper<john.cooper@redhat.com>
> ---
>
> diff --git a/vl.c b/vl.c
> index d69250c..b74cbba 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -1162,7 +1162,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);
>    

You need to explicitly add a null terminator.  Far better to just never 
use strncpy().

Regards,

Anthony Liguori

>       QTAILQ_INSERT_TAIL(&drives, dinfo, next);
>
>       switch(type) {
>
>    

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Qemu-devel] Re: [PATCH 2/4] Add virtio disk identification support
  2010-06-03 19:10 ` [Qemu-devel] " Anthony Liguori
@ 2010-06-04  6:34   ` john cooper
  0 siblings, 0 replies; 3+ messages in thread
From: john cooper @ 2010-06-04  6:34 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: john.cooper, Rusty Russell, Marc Haber, qemu-devel

Anthony Liguori wrote:
> On 03/25/2010 12:33 AM, john cooper wrote:
>> Fix bug which truncated serial string to 8 bytes, nul terminate.
>>
>> Signed-off-by: john cooper<john.cooper@redhat.com>
>> ---
>>
>> diff --git a/vl.c b/vl.c
>> index d69250c..b74cbba 100644
>> --- a/vl.c
>> +++ b/vl.c
>> @@ -1162,7 +1162,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);
>>    
> 
> You need to explicitly add a null terminator.  Far better to just never
> use strncpy().

As previous this is a case where dinfo->serial[] is defined
as BLOCK_SERIAL_STRLEN + 1 bytes as an internal convenience.
Above the context of the patch here is a:

    dinfo = qemu_mallocz(sizeof(*dinfo));

which assures this will do as intended, namely copy all
potential BLOCK_SERIAL_STRLEN bytes and assure they are
nul terminated should the full length be present.

I didn't conjure up the existing logic but rather am 
trying to peacefully coexist with it.

-john

-- 
john.cooper@redhat.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-06-04  6:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-25  5:33 [Qemu-devel] [PATCH 2/4] Add virtio disk identification support john cooper
2010-06-03 19:10 ` [Qemu-devel] " Anthony Liguori
2010-06-04  6:34   ` john cooper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).