From: Kevin Wolf <kwolf@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: pbonzini@redhat.com, qemu-devel@nongnu.org,
Peter Xu <peterx@redhat.com>,
Luiz Capitulino <lcapitulino@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 1/8] qdict: fix unbounded stack for qdict_array_entries
Date: Tue, 8 Mar 2016 11:19:44 +0100 [thread overview]
Message-ID: <20160308101944.GD5807@noname.str.redhat.com> (raw)
In-Reply-To: <87pov5e5w3.fsf@blackfin.pond.sub.org>
Am 08.03.2016 um 09:22 hat Markus Armbruster geschrieben:
> Cc: Kevin, because he added the array in question.
>
> Peter Xu <peterx@redhat.com> writes:
>
> > Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
> > CC: Luiz Capitulino <lcapitulino@redhat.com>
> > Signed-off-by: Peter Xu <peterx@redhat.com>
> > ---
> > qobject/qdict.c | 15 +++++++++------
> > 1 file changed, 9 insertions(+), 6 deletions(-)
> >
> > diff --git a/qobject/qdict.c b/qobject/qdict.c
> > index 9833bd0..eb602a7 100644
> > --- a/qobject/qdict.c
> > +++ b/qobject/qdict.c
> > @@ -704,17 +704,19 @@ 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];
> > +#define __SLEN_MAX (128)
> > + char indexstr[__SLEN_MAX], prefix[__SLEN_MAX];
> > size_t snprintf_ret;
> >
> > - snprintf_ret = snprintf(indexstr, slen, "%s%u", subqdict, i);
> > - assert(snprintf_ret < slen);
> > + assert(__SLEN_MAX >= 32 + subqdict_len);
> > +
> > + snprintf_ret = snprintf(indexstr, __SLEN_MAX, "%s%u", subqdict, i);
> > + assert(snprintf_ret < __SLEN_MAX);
> >
> > subqobj = qdict_get(src, indexstr);
> >
> > - snprintf_ret = snprintf(prefix, slen, "%s%u.", subqdict, i);
> > - assert(snprintf_ret < slen);
> > + snprintf_ret = snprintf(prefix, __SLEN_MAX, "%s%u.", subqdict, i);
> > + assert(snprintf_ret < __SLEN_MAX);
> >
> > subqdict_entries = qdict_count_prefixed_entries(src, prefix);
> > if (subqdict_entries < 0) {
> > @@ -745,6 +747,7 @@ int qdict_array_entries(QDict *src, const char *subqdict)
> > }
> >
> > return i;
> > +#undef __SLEN_MAX
> > }
> >
> > /**
>
> Same arguments as for PATCH 2, except here an argument on the maximum
> length of subqdict would probably be easier.
Yes, these are constant string literals in all callers, including the
one non-test case in quorum.
Let's simply assert a reasonable maximum for subqdict_length. The
minimum we need to allow with the existing callers is 9, and I expect
we'll never get keys longer than 16 characters.
> Unrelated to your patch: I think we've pushed QDict use father than
> sensible. Encoding multiple keys in a string so you can use a flat
> associative array as your catch-all data structure is appropriate in
> AWK, but in C? Not so much...
We'll always to that, because it's the command line syntax. What you may
criticise is that we convert QAPI objects to the command line
representation instead of the other way around, but changing that (which
I think would be far from trivial, for relatively little use) wouldn't
get rid of this kind of key parsing, but just move it a bit closer to
the command line handling.
Kevin
next prev parent reply other threads:[~2016-03-08 10:19 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-08 7:00 [Qemu-devel] [PATCH 0/8] Fix several unbounded stack usage Peter Xu
2016-03-08 7:00 ` [Qemu-devel] [PATCH 1/8] qdict: fix unbounded stack for qdict_array_entries Peter Xu
2016-03-08 8:22 ` Markus Armbruster
2016-03-08 10:19 ` Kevin Wolf [this message]
2016-03-08 16:21 ` Eric Blake
2016-03-08 16:30 ` Kevin Wolf
2016-03-08 16:50 ` Daniel P. Berrange
2016-03-09 2:57 ` Peter Xu
2016-03-09 3:04 ` Eric Blake
2016-03-09 3:27 ` Peter Xu
2016-03-09 9:48 ` Kevin Wolf
2016-03-09 13:23 ` Markus Armbruster
2016-03-09 13:57 ` Kevin Wolf
2016-03-09 21:03 ` Markus Armbruster
2016-03-10 1:30 ` Peter Xu
2016-03-08 7:00 ` [Qemu-devel] [PATCH 2/8] block: fix unbounded stack for dump_qdict Peter Xu
2016-03-08 8:12 ` Markus Armbruster
2016-03-08 8:53 ` Fam Zheng
2016-03-08 13:47 ` Markus Armbruster
2016-03-09 3:00 ` Peter Xu
2016-03-08 9:31 ` Peter Xu
2016-03-08 13:50 ` Markus Armbruster
2016-03-08 12:17 ` Paolo Bonzini
2016-03-09 3:18 ` Peter Xu
2016-03-08 7:00 ` [Qemu-devel] [PATCH 3/8] usb: fix unbounded stack for ohci_td_pkt Peter Xu
2016-03-08 12:20 ` Paolo Bonzini
2016-03-09 4:59 ` Peter Xu
2016-03-08 7:00 ` [Qemu-devel] [PATCH 4/8] usb: fix unbounded stack for xhci_dma_write_u32s Peter Xu
2016-03-08 7:26 ` Peter Maydell
2016-03-09 5:12 ` Peter Xu
2016-03-08 12:21 ` Paolo Bonzini
2016-03-09 5:08 ` Peter Xu
2016-03-09 7:53 ` Paolo Bonzini
2016-03-09 8:07 ` Peter Xu
2016-03-09 8:34 ` Markus Armbruster
2016-03-09 9:19 ` Peter Xu
2016-03-09 12:52 ` Markus Armbruster
2016-03-09 12:59 ` Paolo Bonzini
2016-03-10 2:07 ` Peter Xu
2016-03-08 7:00 ` [Qemu-devel] [PATCH 5/8] usb: fix unbounded stack for inotify_watchfn Peter Xu
2016-03-08 7:20 ` Peter Maydell
2016-03-08 12:22 ` Paolo Bonzini
2016-03-09 5:22 ` Peter Xu
2016-03-08 12:22 ` Paolo Bonzini
2016-03-09 5:23 ` Peter Xu
2016-03-08 7:00 ` [Qemu-devel] [PATCH 6/8] usb: fix unbounded stack for usb_mtp_add_str Peter Xu
2016-03-08 8:10 ` Gerd Hoffmann
2016-03-09 5:29 ` Peter Xu
2016-03-08 7:00 ` [Qemu-devel] [PATCH 7/8] migration: fix unbounded stack for source_return_path_thread Peter Xu
2016-03-08 9:48 ` Juan Quintela
2016-03-08 12:27 ` Paolo Bonzini
2016-03-08 12:26 ` Paolo Bonzini
2016-03-09 5:27 ` Peter Xu
2016-03-08 7:00 ` [Qemu-devel] [PATCH 8/8] hw/i386: fix unbounded stack for load_multiboot Peter Xu
2016-03-08 7:17 ` Peter Maydell
2016-03-08 12:29 ` Paolo Bonzini
2016-03-09 5:39 ` 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=20160308101944.GD5807@noname.str.redhat.com \
--to=kwolf@redhat.com \
--cc=armbru@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterx@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).