All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Cody <jcody@redhat.com>
To: John Snow <jsnow@redhat.com>
Cc: qemu-trivial@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-trivial] [PATCH v2] util/id: fully allocate names table
Date: Wed, 25 Nov 2015 17:07:35 -0500	[thread overview]
Message-ID: <20151125220735.GC2645@localhost.localdomain> (raw)
In-Reply-To: <1448485417-8196-1-git-send-email-jsnow@redhat.com>

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>


WARNING: multiple messages have this Message-ID (diff)
From: Jeff Cody <jcody@redhat.com>
To: John Snow <jsnow@redhat.com>
Cc: qemu-trivial@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2] util/id: fully allocate names table
Date: Wed, 25 Nov 2015 17:07:35 -0500	[thread overview]
Message-ID: <20151125220735.GC2645@localhost.localdomain> (raw)
In-Reply-To: <1448485417-8196-1-git-send-email-jsnow@redhat.com>

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>

  parent reply	other threads:[~2015-11-25 22:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-25 21:03 [Qemu-trivial] [PATCH v2] util/id: fully allocate names table John Snow
2015-11-25 21:03 ` [Qemu-devel] " John Snow
2015-11-25 21:07 ` [Qemu-trivial] " Eric Blake
2015-11-25 21:07   ` Eric Blake
2015-11-25 22:07 ` Jeff Cody [this message]
2015-11-25 22:07   ` Jeff Cody
2015-11-29 10:36 ` [Qemu-trivial] " Michael Tokarev
2015-11-29 10:36   ` [Qemu-devel] " Michael Tokarev

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=20151125220735.GC2645@localhost.localdomain \
    --to=jcody@redhat.com \
    --cc=jsnow@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.