From nobody Fri Oct 3 14:53:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1546857466602536.6066379602458; Mon, 7 Jan 2019 02:37:46 -0800 (PST) Received: from localhost ([127.0.0.1]:57529 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ggSHw-00042n-Mo for importer@patchew.org; Mon, 07 Jan 2019 05:37:44 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35921) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ggSGo-0003Uu-GC for qemu-devel@nongnu.org; Mon, 07 Jan 2019 05:36:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ggSGn-00058h-Nu for qemu-devel@nongnu.org; Mon, 07 Jan 2019 05:36:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40684) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ggSGn-000581-In for qemu-devel@nongnu.org; Mon, 07 Jan 2019 05:36:33 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 85EE958E23; Mon, 7 Jan 2019 10:36:31 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-45.phx2.redhat.com [10.3.116.45]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6CFBA5D9CD; Mon, 7 Jan 2019 10:36:29 +0000 (UTC) From: P J P To: QEMU Developers Date: Mon, 7 Jan 2019 16:04:26 +0530 Message-Id: <20190107103426.2669-1-ppandit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 07 Jan 2019 10:36:31 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] qga: check length of command-line & environment variables X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , niuguoxiang , Prasad J Pandit Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Prasad J Pandit 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 Signed-off-by: Prasad J Pandit --- 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 *entr= y, bool log) int count =3D 1, i =3D 0; /* reserve for NULL terminator */ char **args; char *str; /* for logging array of arguments */ - size_t str_size =3D 1; + size_t str_size =3D 1, args_max; =20 + args_max =3D sysconf(_SC_ARG_MAX); for (it =3D entry; it !=3D NULL; it =3D it->next) { count++; str_size +=3D 1 + strlen(it->value); + if (str_size >=3D args_max / 2 + || count >=3D args_max / sizeof(char *)) { + break; + } } =20 str =3D g_malloc(str_size); *str =3D 0; args =3D g_malloc(count * sizeof(char *)); - for (it =3D entry; it !=3D NULL; it =3D it->next) { + for (it =3D entry; it !=3D NULL && i < count; it =3D it->next) { args[i++] =3D it->value; pstrcat(str, str_size, it->value); if (it->next) { --=20 2.20.1