|
|
a056f39 |
From: Prasad J Pandit <pjp@fedoraproject.org>
|
|
|
a056f39 |
Date: Wed, 13 Jun 2018 11:46:57 +0530
|
|
|
a056f39 |
Subject: [PATCH] qga: check bytes count read by guest-file-read
|
|
|
a056f39 |
|
|
|
a056f39 |
While reading file content via 'guest-file-read' command,
|
|
|
a056f39 |
'qmp_guest_file_read' routine allocates buffer of count+1
|
|
|
a056f39 |
bytes. It could overflow for large values of 'count'.
|
|
|
a056f39 |
Add check to avoid it.
|
|
|
a056f39 |
|
|
|
a056f39 |
Reported-by: Fakhri Zulkifli <mohdfakhrizulkifli@gmail.com>
|
|
|
a056f39 |
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
|
|
|
a056f39 |
Cc: qemu-stable@nongnu.org
|
|
|
a056f39 |
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
|
|
|
a056f39 |
(cherry picked from commit 141b197408ab398c4f474ac1a728ab316e921f2b)
|
|
|
a056f39 |
---
|
|
|
a056f39 |
qga/commands-posix.c | 2 +-
|
|
|
a056f39 |
qga/commands-win32.c | 2 +-
|
|
|
a056f39 |
2 files changed, 2 insertions(+), 2 deletions(-)
|
|
|
a056f39 |
|
|
|
a056f39 |
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
|
|
|
a056f39 |
index ab0c63d931..bcdb808fa3 100644
|
|
|
a056f39 |
--- a/qga/commands-posix.c
|
|
|
a056f39 |
+++ b/qga/commands-posix.c
|
|
|
a056f39 |
@@ -457,7 +457,7 @@ struct GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count,
|
|
|
a056f39 |
|
|
|
a056f39 |
if (!has_count) {
|
|
|
a056f39 |
count = QGA_READ_COUNT_DEFAULT;
|
|
|
a056f39 |
- } else if (count < 0) {
|
|
|
a056f39 |
+ } else if (count < 0 || count >= UINT32_MAX) {
|
|
|
a056f39 |
error_setg(errp, "value '%" PRId64 "' is invalid for argument count",
|
|
|
a056f39 |
count);
|
|
|
a056f39 |
return NULL;
|
|
|
a056f39 |
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
|
|
|
a056f39 |
index 619dbd2bc2..be6fa1a89e 100644
|
|
|
a056f39 |
--- a/qga/commands-win32.c
|
|
|
a056f39 |
+++ b/qga/commands-win32.c
|
|
|
a056f39 |
@@ -315,7 +315,7 @@ GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count,
|
|
|
a056f39 |
}
|
|
|
a056f39 |
if (!has_count) {
|
|
|
a056f39 |
count = QGA_READ_COUNT_DEFAULT;
|
|
|
a056f39 |
- } else if (count < 0) {
|
|
|
a056f39 |
+ } else if (count < 0 || count >= UINT32_MAX) {
|
|
|
a056f39 |
error_setg(errp, "value '%" PRId64
|
|
|
a056f39 |
"' is invalid for argument count", count);
|
|
|
a056f39 |
return NULL;
|