qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, peterx@redhat.com
Subject: [Qemu-devel] [PATCH] qdict: fix unbounded stack for qdict_array_entries
Date: Wed,  9 Mar 2016 14:03:38 +0800	[thread overview]
Message-ID: <1457503418-31299-1-git-send-email-peterx@redhat.com> (raw)

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-09  6:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-09  6:03 Peter Xu [this message]
2016-03-10  1:36 ` [Qemu-devel] [PATCH] qdict: fix unbounded stack for qdict_array_entries Peter Xu
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=1457503418-31299-1-git-send-email-peterx@redhat.com \
    --to=peterx@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).