From: P J P <ppandit@redhat.com>
To: QEMU Developers <qemu-devel@nongnu.org>
Cc: Michael Roth <mdroth@linux.vnet.ibm.com>,
niuguoxiang <niuguoxiang@huawei.com>,
Prasad J Pandit <pjp@fedoraproject.org>
Subject: [Qemu-devel] [PATCH] qga: check length of command-line & environment variables
Date: Mon, 7 Jan 2019 16:04:26 +0530 [thread overview]
Message-ID: <20190107103426.2669-1-ppandit@redhat.com> (raw)
From: Prasad J Pandit <pjp@fedoraproject.org>
Qemu guest agent while executing user commands does not seem to
check length of argument list and/or environment variables passed.
It may lead to integer overflow or infinite loop issues. Add check
to avoid it.
Reported-by: Niu Guoxiang <niuguoxiang@huawei.com>
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
---
qga/commands.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/qga/commands.c b/qga/commands.c
index 0c7d1385c2..6d684ef209 100644
--- a/qga/commands.c
+++ b/qga/commands.c
@@ -231,17 +231,22 @@ static char **guest_exec_get_args(const strList *entry, bool log)
int count = 1, i = 0; /* reserve for NULL terminator */
char **args;
char *str; /* for logging array of arguments */
- size_t str_size = 1;
+ size_t str_size = 1, args_max;
+ args_max = sysconf(_SC_ARG_MAX);
for (it = entry; it != NULL; it = it->next) {
count++;
str_size += 1 + strlen(it->value);
+ if (str_size >= args_max / 2
+ || count >= args_max / sizeof(char *)) {
+ break;
+ }
}
str = g_malloc(str_size);
*str = 0;
args = g_malloc(count * sizeof(char *));
- for (it = entry; it != NULL; it = it->next) {
+ for (it = entry; it != NULL && i < count; it = it->next) {
args[i++] = it->value;
pstrcat(str, str_size, it->value);
if (it->next) {
--
2.20.1
next reply other threads:[~2019-01-07 10:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-07 10:34 P J P [this message]
2019-01-07 13:04 ` [Qemu-devel] [PATCH] qga: check length of command-line & environment variables no-reply
2019-01-11 9:52 ` P J P
2019-01-11 9:56 ` Daniel P. Berrangé
2019-01-13 17:28 ` P J P
2019-01-22 3:49 ` [Qemu-devel] 答复: " niuguoxiang
2019-01-24 17:38 ` [Qemu-devel] " Michael Roth
2019-01-24 17:53 ` P J P
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=20190107103426.2669-1-ppandit@redhat.com \
--to=ppandit@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=niuguoxiang@huawei.com \
--cc=pjp@fedoraproject.org \
--cc=qemu-devel@nongnu.org \
/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 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.