[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [trivial for-2.6] util/id: fully allocate names table
From: |
Markus Armbruster |
Subject: |
Re: [Qemu-devel] [trivial for-2.6] util/id: fully allocate names table |
Date: |
Wed, 25 Nov 2015 09:18:13 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) |
John Snow <address@hidden> 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);
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 <address@hidden>
> ---
> 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",
> };