From: John Snow <jsnow@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: qemu-trivial@nongnu.org, jcody@redhat.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-trivial] [Qemu-devel] [trivial for-2.6] util/id: fully allocate names table
Date: Wed, 25 Nov 2015 10:17:54 -0500 [thread overview]
Message-ID: <5655D122.8010601@redhat.com> (raw)
In-Reply-To: <871tbeijay.fsf@blackfin.pond.sub.org>
On 11/25/2015 03:18 AM, Markus Armbruster wrote:
> John Snow <jsnow@redhat.com> writes:
>
>> Trivial: this array should be allocated to have ID_MAX entries always.
>> Otherwise if someone were to forget to expand this table, the assertion
>> in the id generator won't actually trigger; it will read junk data.
>
> You mean this one:
>
> assert(id < ID_MAX);
>
Well, sort of. I meant 'assert(id_subsys_str[id])' itself. If you forget
to expand the list (It happened to a friend of mine) this assert will
pass because it reads garbage.
If you just always expand the full table, though, it will catch you
(Err, my friend) being a dummy a little more nicely.
My thought is we need both the range and presence checks.
I'll v2 it, thanks.
--js
> The assertion is crap, because it fails to protect array access
> id_subsys_str[id]. Here's one that does:
>
> assert(0 <= id && id < ARRAY_SIZE(id_subsys_str));
>
>> Signed-off-by: John Snow <jsnow@redhat.com>
>> ---
>> util/id.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/util/id.c b/util/id.c
>> index bcc64d8..b7ca4d2 100644
>> --- a/util/id.c
>> +++ b/util/id.c
>> @@ -29,7 +29,7 @@ bool id_wellformed(const char *id)
>>
>> #define ID_SPECIAL_CHAR '#'
>>
>> -static const char *const id_subsys_str[] = {
>> +static const char *const id_subsys_str[ID_MAX] = {
>> [ID_QDEV] = "qdev",
>> [ID_BLOCK] = "block",
>> };
WARNING: multiple messages have this Message-ID (diff)
From: John Snow <jsnow@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: qemu-trivial@nongnu.org, jcody@redhat.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [trivial for-2.6] util/id: fully allocate names table
Date: Wed, 25 Nov 2015 10:17:54 -0500 [thread overview]
Message-ID: <5655D122.8010601@redhat.com> (raw)
In-Reply-To: <871tbeijay.fsf@blackfin.pond.sub.org>
On 11/25/2015 03:18 AM, Markus Armbruster wrote:
> John Snow <jsnow@redhat.com> writes:
>
>> Trivial: this array should be allocated to have ID_MAX entries always.
>> Otherwise if someone were to forget to expand this table, the assertion
>> in the id generator won't actually trigger; it will read junk data.
>
> You mean this one:
>
> assert(id < ID_MAX);
>
Well, sort of. I meant 'assert(id_subsys_str[id])' itself. If you forget
to expand the list (It happened to a friend of mine) this assert will
pass because it reads garbage.
If you just always expand the full table, though, it will catch you
(Err, my friend) being a dummy a little more nicely.
My thought is we need both the range and presence checks.
I'll v2 it, thanks.
--js
> The assertion is crap, because it fails to protect array access
> id_subsys_str[id]. Here's one that does:
>
> assert(0 <= id && id < ARRAY_SIZE(id_subsys_str));
>
>> Signed-off-by: John Snow <jsnow@redhat.com>
>> ---
>> util/id.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/util/id.c b/util/id.c
>> index bcc64d8..b7ca4d2 100644
>> --- a/util/id.c
>> +++ b/util/id.c
>> @@ -29,7 +29,7 @@ bool id_wellformed(const char *id)
>>
>> #define ID_SPECIAL_CHAR '#'
>>
>> -static const char *const id_subsys_str[] = {
>> +static const char *const id_subsys_str[ID_MAX] = {
>> [ID_QDEV] = "qdev",
>> [ID_BLOCK] = "block",
>> };
next prev parent reply other threads:[~2015-11-25 15:18 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-24 23:27 [Qemu-trivial] [trivial for-2.6] util/id: fully allocate names table John Snow
2015-11-24 23:27 ` [Qemu-devel] " John Snow
2015-11-25 8:18 ` [Qemu-trivial] " Markus Armbruster
2015-11-25 8:18 ` Markus Armbruster
2015-11-25 9:41 ` [Qemu-trivial] " Kevin Wolf
2015-11-25 9:41 ` Kevin Wolf
2015-11-25 10:27 ` [Qemu-trivial] " Markus Armbruster
2015-11-25 10:27 ` Markus Armbruster
2015-11-25 15:17 ` John Snow [this message]
2015-11-25 15:17 ` John Snow
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=5655D122.8010601@redhat.com \
--to=jsnow@redhat.com \
--cc=armbru@redhat.com \
--cc=jcody@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
/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.