From nobody Mon Feb 9 08:57:24 2026 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; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547374070808401.56940823376215; Sun, 13 Jan 2019 02:07:50 -0800 (PST) Received: from localhost ([127.0.0.1]:60913 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gicg3-0006de-El for importer@patchew.org; Sun, 13 Jan 2019 05:07:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:33757) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1giceJ-0005lz-Pm for qemu-devel@nongnu.org; Sun, 13 Jan 2019 05:05:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1giceI-0003Tg-JB for qemu-devel@nongnu.org; Sun, 13 Jan 2019 05:05:47 -0500 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:39010) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1giceH-0003SV-No for qemu-devel@nongnu.org; Sun, 13 Jan 2019 05:05:46 -0500 Received: by mail-wr1-x441.google.com with SMTP id t27so19596596wra.6 for ; Sun, 13 Jan 2019 02:05:45 -0800 (PST) Received: from bark.daynix ([141.226.163.173]) by smtp.gmail.com with ESMTPSA id j8sm62540340wmd.0.2019.01.13.02.05.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 13 Jan 2019 02:05:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4y8IX/PTbaSNnmt6YfKxNBI0mWnpg3gIlKzBnlx4MoI=; b=WOc8vSR8rKweq0+Lyb0TvKrrwrxAHawPLgiWz0CONeaIUNt81gSPdTnG0CWDytl9nq y5HpJN+yYBLP3SxiKy17HNlItxa4i957TdyuDcC1VZqWD4ZC/PlvFDPiuZhG4+JC0beI +2jKau0zSDTdI1+efwRXRqOO4sVJpMQO1Fxx62/cpcM5XyKXjFCKmEZIeBPIHJMUaKL5 I5z51rKu00767x0+8Bv4R7iUltBfFdJT3yyW7N6929iVtbiLdP8GsCBB4DN18Hg9Gauv t/rQFRTj9X2wbEKjfC4qrKHRBbZMoiEZWQWQbc8/CCeC+Q2JqIkE98jN/xD42N0rVEtf e1DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4y8IX/PTbaSNnmt6YfKxNBI0mWnpg3gIlKzBnlx4MoI=; b=nCzMpm0lHyoRogGR72MnTh/2oePu5xh9xqCSw8rJc+W5r4p9s/6f5Rh9Sy48JwVj9h ANNy8fBA05202J7ei7fp1nRfyNa8dQxCYrzsdsJWFOkh4qXOIv0B5sUA534k5iC16vAB e4uX27HjvU3JGFQnoA/+qc9mey3TP/5D8d5zhtTFHtoCnBgdOggMU4GGrXADGpqIV0Al O65HyabXDMc00T4xjrBy2HuyuiiQMIg/NHhJ15DOly/E5qseZqOYCrATh8q7njH0QROU JIRCtrDX0sAzE6wgA6XlE5V2BYHiN3yGEc1Vg3Uivy7p+4jHDSAUAy8Yo+qofQDLjYy3 /WyQ== X-Gm-Message-State: AJcUukfqUnkvJRoja8O0MD35KMHoEDxpkxe5P4+0NQpJyLcsKlHhoKLG M9i6e9qNlYhhjEg+r34QISsWe/gdrj4= X-Google-Smtp-Source: ALg8bN6dxKDiDV/WalOuimGL+sB9X75Nx8LJJBLtBHusj/1wF/1ywzrFwmTGDnZ40hwRz0mWqgmz+Q== X-Received: by 2002:a5d:4046:: with SMTP id w6mr21029217wrp.92.1547373943866; Sun, 13 Jan 2019 02:05:43 -0800 (PST) From: Basil Salman To: qemu-devel@nongnu.org, Michael Roth Date: Sun, 13 Jan 2019 12:05:28 +0200 Message-Id: <20190113100531.1346024-2-basil@daynix.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190113100531.1346024-1-basil@daynix.com> References: <20190113100531.1346024-1-basil@daynix.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 Subject: [Qemu-devel] [PATCH v2 1/4] qga-win: prevent crash when executing guest-file-read with large count 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: Yan Vugenfirer , Bishara AbuHattoum Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" BZ: #1594054 guest-file-read command is currently implelmented to read from a file handle count number of bytes. when executed with a very large count nu= mber qemu-ga crashes. after some digging turns out that qemu-ga crashes after trying to allocate a buffer large enough to save the data read in it, the buffer was allocated= using g_malloc0 which is not fail safe, and results a crash in case of failure. g_malloc0 was replaced with g_try_malloc0() which returns NULL on failure, A check was added for that case in order to prevent qemu-ga from crashing and to send a response to the qemu-ga client accordingly. Signed-off-by: Basil Salman --- qga/commands-win32.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 62e1b51dfe..4260faa573 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -345,7 +345,13 @@ GuestFileRead *qmp_guest_file_read(int64_t handle, boo= l has_count, } =20 fh =3D gfh->fh; - buf =3D g_malloc0(count+1); + buf =3D g_try_malloc0(count + 1); + if (!buf) { + error_setg(errp, + "failed to allocate sufficient memory" + "to complete the requested service"); + return read_data; + } is_ok =3D ReadFile(fh, buf, count, &read_count, NULL); if (!is_ok) { error_setg_win32(errp, GetLastError(), "failed to read file"); --=20 2.17.2