* [Qemu-devel] [PATCH v2] util/id: fully allocate names table
@ 2015-11-25 21:03 John Snow
2015-11-25 21:07 ` Eric Blake
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: John Snow @ 2015-11-25 21:03 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial, jcody, John Snow
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.
v2: Fix the range assertion, too. Compare against the known actual size
of the table instead of what it "should" be.
Signed-off-by: John Snow <jsnow@redhat.com>
---
util/id.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/util/id.c b/util/id.c
index bcc64d8..7883fbe 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",
};
@@ -53,7 +53,7 @@ char *id_generate(IdSubSystems id)
static uint64_t id_counters[ID_MAX];
uint32_t rnd;
- assert(id < ID_MAX);
+ assert(id < ARRAY_SIZE(id_subsys_str));
assert(id_subsys_str[id]);
rnd = g_random_int_range(0, 100);
--
2.4.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH v2] util/id: fully allocate names table
2015-11-25 21:03 [Qemu-devel] [PATCH v2] util/id: fully allocate names table John Snow
@ 2015-11-25 21:07 ` Eric Blake
2015-11-25 22:07 ` Jeff Cody
2015-11-29 10:36 ` Michael Tokarev
2 siblings, 0 replies; 4+ messages in thread
From: Eric Blake @ 2015-11-25 21:07 UTC (permalink / raw)
To: John Snow, qemu-devel; +Cc: qemu-trivial, jcody
[-- Attachment #1: Type: text/plain, Size: 777 bytes --]
On 11/25/2015 02:03 PM, John Snow wrote:
> 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.
>
> v2: Fix the range assertion, too. Compare against the known actual size
> of the table instead of what it "should" be.
The v2 blurb would normally appear after the ---; it can be removed by
the maintainer.
>
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
> util/id.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH v2] util/id: fully allocate names table
2015-11-25 21:03 [Qemu-devel] [PATCH v2] util/id: fully allocate names table John Snow
2015-11-25 21:07 ` Eric Blake
@ 2015-11-25 22:07 ` Jeff Cody
2015-11-29 10:36 ` Michael Tokarev
2 siblings, 0 replies; 4+ messages in thread
From: Jeff Cody @ 2015-11-25 22:07 UTC (permalink / raw)
To: John Snow; +Cc: qemu-trivial, qemu-devel
On Wed, Nov 25, 2015 at 04:03:37PM -0500, John Snow wrote:
> 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.
>
> v2: Fix the range assertion, too. Compare against the known actual size
> of the table instead of what it "should" be.
>
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
> util/id.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/util/id.c b/util/id.c
> index bcc64d8..7883fbe 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",
> };
> @@ -53,7 +53,7 @@ char *id_generate(IdSubSystems id)
> static uint64_t id_counters[ID_MAX];
> uint32_t rnd;
>
> - assert(id < ID_MAX);
> + assert(id < ARRAY_SIZE(id_subsys_str));
> assert(id_subsys_str[id]);
>
> rnd = g_random_int_range(0, 100);
> --
> 2.4.3
>
Reviewed-by: Jeff Cody <jcody@redhat.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH v2] util/id: fully allocate names table
2015-11-25 21:03 [Qemu-devel] [PATCH v2] util/id: fully allocate names table John Snow
2015-11-25 21:07 ` Eric Blake
2015-11-25 22:07 ` Jeff Cody
@ 2015-11-29 10:36 ` Michael Tokarev
2 siblings, 0 replies; 4+ messages in thread
From: Michael Tokarev @ 2015-11-29 10:36 UTC (permalink / raw)
To: John Snow, qemu-devel; +Cc: qemu-trivial, jcody
26.11.2015 00:03, John Snow wrote:
> 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.
Applied to -trivial as a bugfix, with a trivial commit description
cleanup, removing this part:
> v2: Fix the range assertion, too. Compare against the known actual size
> of the table instead of what it "should" be.
Thanks!
/mjt
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-11-29 10:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-25 21:03 [Qemu-devel] [PATCH v2] util/id: fully allocate names table John Snow
2015-11-25 21:07 ` Eric Blake
2015-11-25 22:07 ` Jeff Cody
2015-11-29 10:36 ` Michael Tokarev
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).