From: Basil Salman <basil@daynix.com>
To: qemu-devel@nongnu.org, Michael Roth <mdroth@linux.vnet.ibm.com>
Cc: Yan Vugenfirer <yan@daynix.com>, Bishara AbuHattoum <bishara@daynix.com>
Subject: [Qemu-devel] [PATCH v2 1/4] qga-win: prevent crash when executing guest-file-read with large count
Date: Sun, 13 Jan 2019 12:05:28 +0200 [thread overview]
Message-ID: <20190113100531.1346024-2-basil@daynix.com> (raw)
In-Reply-To: <20190113100531.1346024-1-basil@daynix.com>
BZ: #1594054
guest-file-read command is currently implelmented to read from a
file handle count number of bytes. when executed with a very large count number
qemu-ga crashes.
after some digging turns out that qemu-ga crashes after trying to allocate
a buffer large enough to save the data read in it, the buffer was allocated using
g_malloc0 which is not fail safe, and results a crash in case of failure.
g_malloc0 was replaced with g_try_malloc0() which returns NULL on failure,
A check was added for that case in order to prevent qemu-ga from crashing
and to send a response to the qemu-ga client accordingly.
Signed-off-by: Basil Salman <basil@daynix.com>
---
qga/commands-win32.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 62e1b51dfe..4260faa573 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -345,7 +345,13 @@ GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count,
}
fh = gfh->fh;
- buf = g_malloc0(count+1);
+ buf = g_try_malloc0(count + 1);
+ if (!buf) {
+ error_setg(errp,
+ "failed to allocate sufficient memory"
+ "to complete the requested service");
+ return read_data;
+ }
is_ok = ReadFile(fh, buf, count, &read_count, NULL);
if (!is_ok) {
error_setg_win32(errp, GetLastError(), "failed to read file");
--
2.17.2
next prev parent reply other threads:[~2019-01-13 10:05 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-13 10:05 [Qemu-devel] [PATCH v2 0/4] QGA - Win fixes Basil Salman
2019-01-13 10:05 ` Basil Salman [this message]
2019-01-24 16:44 ` [Qemu-devel] [PATCH v2 1/4] qga-win: prevent crash when executing guest-file-read with large count Michael Roth
2019-01-13 10:05 ` [Qemu-devel] [PATCH v2 2/4] qga: fix send_response error handling Basil Salman
2019-01-24 17:18 ` Michael Roth
2019-01-13 10:05 ` [Qemu-devel] [PATCH v2 3/4] qga: Installer: Wait for installation to finish Basil Salman
2019-01-13 10:05 ` [Qemu-devel] [PATCH v2 4/4] qga-win: Handle VSS_E_PROVIDER_ALREADY_REGISTERED error Basil Salman
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=20190113100531.1346024-2-basil@daynix.com \
--to=basil@daynix.com \
--cc=bishara@daynix.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=yan@daynix.com \
/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).