All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH-for-5.0] qga-posix: Avoid crashing process when failing to allocate memory
@ 2020-03-24 19:48 ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 22+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-03-24 19:48 UTC (permalink / raw)
  To: qemu-devel
  Cc: Sameeh Jubran, Basil Salman, qemu-trivial, Michael Roth,
	Philippe Mathieu-Daudé, qemu-stable, Fakhri Zulkifli

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



^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2020-03-31 13:34 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-24 19:48 [PATCH-for-5.0] qga-posix: Avoid crashing process when failing to allocate memory Philippe Mathieu-Daudé
2020-03-24 19:48 ` Philippe Mathieu-Daudé
2020-03-25  6:19 ` Dietmar Maurer
2020-03-25  6:19   ` Dietmar Maurer
2020-03-25 12:10   ` Philippe Mathieu-Daudé
2020-03-25 12:10     ` Philippe Mathieu-Daudé
2020-03-30 14:11     ` Markus Armbruster
2020-03-30 14:11       ` Markus Armbruster
2020-03-30 16:04       ` Philippe Mathieu-Daudé
2020-03-30 16:04         ` Philippe Mathieu-Daudé
2020-03-30 16:08         ` Philippe Mathieu-Daudé
2020-03-30 16:08           ` Philippe Mathieu-Daudé
2020-03-30 16:38         ` Dr. David Alan Gilbert
2020-03-30 16:38           ` Dr. David Alan Gilbert
2020-03-30 16:47           ` Daniel P. Berrangé
2020-03-30 16:47             ` Daniel P. Berrangé
2020-03-30 17:06         ` Daniel P. Berrangé
2020-03-30 17:06           ` Daniel P. Berrangé
2020-03-31 13:32           ` Philippe Mathieu-Daudé
2020-03-31 13:32             ` Philippe Mathieu-Daudé
2020-03-30 16:25 ` Daniel P. Berrangé
2020-03-30 16:25   ` Daniel P. Berrangé

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.