qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	pbonzini@redhat.com, Markus Armbruster <armbru@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] qdict: fix unbounded stack for qdict_array_entries
Date: Thu, 10 Mar 2016 09:36:05 +0800	[thread overview]
Message-ID: <20160310013605.GD4091@pxdev.xzpeter.org> (raw)
In-Reply-To: <1457503418-31299-1-git-send-email-peterx@redhat.com>

Sorry to forgot CCing Eric/Markus/Kevin.

This patch title is not correct, which should be:

"Fix unbounded stack warning for qdict_array_entries"

Do I need to re-send with the same content?

I'm using g_strdup_printf() here, considering it's most convenient,
safe, and as long as it's called rarely only when quorum device
opens.

Thanks.
Peter

On Wed, Mar 09, 2016 at 02:03:38PM +0800, Peter Xu wrote:
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>  qobject/qdict.c | 15 ++++++---------
>  1 file changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/qobject/qdict.c b/qobject/qdict.c
> index 9833bd0..9188a87 100644
> --- a/qobject/qdict.c
> +++ b/qobject/qdict.c
> @@ -704,19 +704,16 @@ int qdict_array_entries(QDict *src, const char *subqdict)
>      for (i = 0; i < INT_MAX; i++) {
>          QObject *subqobj;
>          int subqdict_entries;
> -        size_t slen = 32 + subqdict_len;
> -        char indexstr[slen], prefix[slen];
> -        size_t snprintf_ret;
> +        char *prefix = g_strdup_printf("%s%u.", subqdict, i);
>  
> -        snprintf_ret = snprintf(indexstr, slen, "%s%u", subqdict, i);
> -        assert(snprintf_ret < slen);
> +        subqdict_entries = qdict_count_prefixed_entries(src, prefix);
>  
> -        subqobj = qdict_get(src, indexstr);
> +        /* Remove ending "." */
> +        prefix[strlen(prefix) - 1] = 0x00;
> +        subqobj = qdict_get(src, prefix);
>  
> -        snprintf_ret = snprintf(prefix, slen, "%s%u.", subqdict, i);
> -        assert(snprintf_ret < slen);
> +        g_free(prefix);
>  
> -        subqdict_entries = qdict_count_prefixed_entries(src, prefix);
>          if (subqdict_entries < 0) {
>              return subqdict_entries;
>          }
> -- 
> 2.4.3
> 

  reply	other threads:[~2016-03-10  1:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-09  6:03 [Qemu-devel] [PATCH] qdict: fix unbounded stack for qdict_array_entries Peter Xu
2016-03-10  1:36 ` Peter Xu [this message]
2016-03-21 20:58   ` Eric Blake
2016-03-22  2:25     ` Peter Xu

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=20160310013605.GD4091@pxdev.xzpeter.org \
    --to=peterx@redhat.com \
    --cc=armbru@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@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 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).