[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH-for-5.0] qga-posix: Avoid crashing process when failing to alloca
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH-for-5.0] qga-posix: Avoid crashing process when failing to allocate memory |
Date: |
Tue, 24 Mar 2020 20:48:36 +0100 |
Similarly to commit 807e2b6fce0 for Windows, kindly return a
QMP error message instead of crashing the whole process.
Cc: address@hidden
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1594054
Reported-by: Fakhri Zulkifli <address@hidden>
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
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
- [PATCH-for-5.0] qga-posix: Avoid crashing process when failing to allocate memory,
Philippe Mathieu-Daudé <=
- Re: [PATCH-for-5.0] qga-posix: Avoid crashing process when failing to allocate memory, Dietmar Maurer, 2020/03/25
- Re: [PATCH-for-5.0] qga-posix: Avoid crashing process when failing to allocate memory, Philippe Mathieu-Daudé, 2020/03/25
- Re: [PATCH-for-5.0] qga-posix: Avoid crashing process when failing to allocate memory, Markus Armbruster, 2020/03/30
- Re: [PATCH-for-5.0] qga-posix: Avoid crashing process when failing to allocate memory, Philippe Mathieu-Daudé, 2020/03/30
- Re: [PATCH-for-5.0] qga-posix: Avoid crashing process when failing to allocate memory, Philippe Mathieu-Daudé, 2020/03/30
- Re: [PATCH-for-5.0] qga-posix: Avoid crashing process when failing to allocate memory, Dr. David Alan Gilbert, 2020/03/30
- Re: [PATCH-for-5.0] qga-posix: Avoid crashing process when failing to allocate memory, Daniel P . Berrangé, 2020/03/30
- Re: [PATCH-for-5.0] qga-posix: Avoid crashing process when failing to allocate memory, Daniel P . Berrangé, 2020/03/30
- Re: [PATCH-for-5.0] qga-posix: Avoid crashing process when failing to allocate memory, Philippe Mathieu-Daudé, 2020/03/31
Re: [PATCH-for-5.0] qga-posix: Avoid crashing process when failing to allocate memory, Daniel P . Berrangé, 2020/03/30