From: Prasad J Pandit Date: Wed, 13 Jun 2018 06:16:57 +0000 (+0530) Subject: qga: check bytes count read by guest-file-read X-Git-Tag: v3.0.0-rc0~22^2~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=141b197408ab398c4f474ac1a728ab316e921f2b;p=thirdparty%2Fqemu.git qga: check bytes count read by guest-file-read While reading file content via 'guest-file-read' command, 'qmp_guest_file_read' routine allocates buffer of count+1 bytes. It could overflow for large values of 'count'. Add check to avoid it. Reported-by: Fakhri Zulkifli Signed-off-by: Prasad J Pandit Cc: qemu-stable@nongnu.org Signed-off-by: Michael Roth --- diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 594d21ef3e3..9284e716669 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -458,7 +458,7 @@ struct GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count, if (!has_count) { count = QGA_READ_COUNT_DEFAULT; - } else if (count < 0) { + } else if (count < 0 || count >= UINT32_MAX) { error_setg(errp, "value '%" PRId64 "' is invalid for argument count", count); return NULL; diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 70ee5379f64..73f31fa8c25 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -318,7 +318,7 @@ GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count, } if (!has_count) { count = QGA_READ_COUNT_DEFAULT; - } else if (count < 0) { + } else if (count < 0 || count >= UINT32_MAX) { error_setg(errp, "value '%" PRId64 "' is invalid for argument count", count); return NULL;