From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: liujunjie <liujunjie23@huawei.com>
Subject: [Qemu-devel] [PULL v2 1/3] qstring: Fix qstring_from_substr() not to provoke int overflow
Date: Sat, 28 Jul 2018 09:16:36 +0200 [thread overview]
Message-ID: <20180728071638.17077-2-armbru@redhat.com> (raw)
In-Reply-To: <20180728071638.17077-1-armbru@redhat.com>
From: liujunjie <liujunjie23@huawei.com>
qstring_from_substr() parameters @start and @end are of type int.
blkdebug_parse_filename(), blkverify_parse_filename(), nbd_parse_uri(),
and qstring_from_str() pass @end values of type size_t or ptrdiff_t.
Values exceeding INT_MAX get truncated, with possibly disastrous
results.
Such huge substrings seem unlikely, but we found one in a core dump,
where "info tlb" executed via QMP's human-monitor-command apparently
produced 35 GiB of output.
Fix by changing the parameters size_t.
Signed-off-by: liujunjie <liujunjie23@huawei.com>
Message-Id: <20180724134339.17832-1-liujunjie23@huawei.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
include/qapi/qmp/qstring.h | 2 +-
qobject/qstring.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/qapi/qmp/qstring.h b/include/qapi/qmp/qstring.h
index b3b3d444d2..3e83e3a95d 100644
--- a/include/qapi/qmp/qstring.h
+++ b/include/qapi/qmp/qstring.h
@@ -24,7 +24,7 @@ struct QString {
QString *qstring_new(void);
QString *qstring_from_str(const char *str);
-QString *qstring_from_substr(const char *str, int start, int end);
+QString *qstring_from_substr(const char *str, size_t start, size_t end);
size_t qstring_get_length(const QString *qstring);
const char *qstring_get_str(const QString *qstring);
const char *qstring_get_try_str(const QString *qstring);
diff --git a/qobject/qstring.c b/qobject/qstring.c
index afca54b47a..18b8eb82f8 100644
--- a/qobject/qstring.c
+++ b/qobject/qstring.c
@@ -37,7 +37,7 @@ size_t qstring_get_length(const QString *qstring)
*
* Return string reference
*/
-QString *qstring_from_substr(const char *str, int start, int end)
+QString *qstring_from_substr(const char *str, size_t start, size_t end)
{
QString *qstring;
--
2.17.1
next prev parent reply other threads:[~2018-07-28 7:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-28 7:16 [Qemu-devel] [PULL v2 0/3] QObject patches for 2018-07-27 (3.0.0-rc3) Markus Armbruster
2018-07-28 7:16 ` Markus Armbruster [this message]
2018-07-28 7:16 ` [Qemu-devel] [PULL v2 2/3] qstring: Assert size calculations don't overflow Markus Armbruster
2018-07-28 7:16 ` [Qemu-devel] [PULL v2 3/3] qstring: Move qstring_from_substr()'s @end one to the right Markus Armbruster
2018-07-30 9:24 ` [Qemu-devel] [PULL v2 0/3] QObject patches for 2018-07-27 (3.0.0-rc3) Peter Maydell
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=20180728071638.17077-2-armbru@redhat.com \
--to=armbru@redhat.com \
--cc=liujunjie23@huawei.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).