From: john cooper <john.cooper@redhat.com>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: john.cooper@redhat.com, Rusty Russell <rusty@rustcorp.com.au>,
Marc Haber <mh+qemu-devel@zugschlus.de>,
qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [PATCH 2/4] Add virtio disk identification support
Date: Fri, 04 Jun 2010 02:34:42 -0400 [thread overview]
Message-ID: <4C089E82.3040000@redhat.com> (raw)
In-Reply-To: <4C07FE08.9020708@codemonkey.ws>
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
prev parent reply other threads:[~2010-06-04 6:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4C089E82.3040000@redhat.com \
--to=john.cooper@redhat.com \
--cc=anthony@codemonkey.ws \
--cc=mh+qemu-devel@zugschlus.de \
--cc=qemu-devel@nongnu.org \
--cc=rusty@rustcorp.com.au \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.