qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Dietmar Maurer <dietmar@proxmox.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 13:10:11 +0100	[thread overview]
Message-ID: <6be54d1f-e5fc-5b34-ba4d-fa050029f26b@redhat.com> (raw)
In-Reply-To: <1242083041.1.1585117162620@webmail.proxmox.com>

On 3/25/20 7:19 AM, Dietmar Maurer wrote:
> but error_setg() also calls malloc, so this does not help at all?

IIUC the problem, you can send a QMP command to ask to read let's say 
3GB of a file, and QEMU crashes. But this doesn't mean there the .heap 
is empty, there is probably few bytes still available, enough to respond 
with an error message.

> 
>> 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
> 



  reply	other threads:[~2020-03-25 12:11 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
2020-03-25 12:10   ` Philippe Mathieu-Daudé [this message]
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=6be54d1f-e5fc-5b34-ba4d-fa050029f26b@redhat.com \
    --to=philmd@redhat.com \
    --cc=basil@daynix.com \
    --cc=dietmar@proxmox.com \
    --cc=mohdfakhrizulkifli@gmail.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).