From: Dietmar Maurer <dietmar@proxmox.com>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>, qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, Sameeh Jubran <sjubran@redhat.com>,
qemu-stable@nongnu.org,
Fakhri Zulkifli <mohdfakhrizulkifli@gmail.com>,
Basil Salman <basil@daynix.com>
Subject: Re: [PATCH-for-5.0] qga-posix: Avoid crashing process when failing to allocate memory
Date: Wed, 25 Mar 2020 07:19:22 +0100 (CET) [thread overview]
Message-ID: <1242083041.1.1585117162620@webmail.proxmox.com> (raw)
In-Reply-To: <20200324194836.21539-1-philmd@redhat.com>
but error_setg() also calls malloc, so this does not help at all?
> On March 24, 2020 8:48 PM Philippe Mathieu-Daudé <philmd@redhat.com> wrote:
>
>
> Similarly to commit 807e2b6fce0 for Windows, kindly return a
> QMP error message instead of crashing the whole process.
>
> Cc: qemu-stable@nongnu.org
> Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1594054
> Reported-by: Fakhri Zulkifli <mohdfakhrizulkifli@gmail.com>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> qga/commands-posix.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/qga/commands-posix.c b/qga/commands-posix.c
> index 93474ff770..8f127788e6 100644
> --- a/qga/commands-posix.c
> +++ b/qga/commands-posix.c
> @@ -493,7 +493,13 @@ struct GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count,
> gfh->state = RW_STATE_NEW;
> }
>
> - 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 NULL;
> + }
> read_count = fread(buf, 1, count, fh);
> if (ferror(fh)) {
> error_setg_errno(errp, errno, "failed to read file");
> --
> 2.21.1
next prev parent reply other threads:[~2020-03-25 6:20 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-24 19:48 [PATCH-for-5.0] qga-posix: Avoid crashing process when failing to allocate memory Philippe Mathieu-Daudé
2020-03-25 6:19 ` Dietmar Maurer [this message]
2020-03-25 12:10 ` Philippe Mathieu-Daudé
2020-03-30 14:11 ` Markus Armbruster
2020-03-30 16:04 ` Philippe Mathieu-Daudé
2020-03-30 16:08 ` Philippe Mathieu-Daudé
2020-03-30 16:38 ` Dr. David Alan Gilbert
2020-03-30 16:47 ` Daniel P. Berrangé
2020-03-30 17:06 ` Daniel P. Berrangé
2020-03-31 13:32 ` Philippe Mathieu-Daudé
2020-03-30 16:25 ` Daniel P. Berrangé
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=1242083041.1.1585117162620@webmail.proxmox.com \
--to=dietmar@proxmox.com \
--cc=basil@daynix.com \
--cc=mohdfakhrizulkifli@gmail.com \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=sjubran@redhat.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).