From nobody Thu Nov 6 18:07:56 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1542310062172136.75989150449925; Thu, 15 Nov 2018 11:27:42 -0800 (PST) Received: from localhost ([::1]:40440 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNNIb-0004ll-LQ for importer@patchew.org; Thu, 15 Nov 2018 14:27:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56161) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNNGF-0003Ro-Ff for qemu-devel@nongnu.org; Thu, 15 Nov 2018 14:25:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNNG4-0007zi-18 for qemu-devel@nongnu.org; Thu, 15 Nov 2018 14:25:07 -0500 Received: from mail-ot1-x341.google.com ([2607:f8b0:4864:20::341]:33275) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gNNG3-0007zP-Ou for qemu-devel@nongnu.org; Thu, 15 Nov 2018 14:24:55 -0500 Received: by mail-ot1-x341.google.com with SMTP id i20so12635634otl.0 for ; Thu, 15 Nov 2018 11:24:55 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id p189-v6sm3454125oif.19.2018.11.15.11.24.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Nov 2018 11:24:53 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 35871F61; Thu, 15 Nov 2018 13:24:50 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 88BBC301465; Thu, 15 Nov 2018 13:24:48 -0600 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=m+ciRRszxYVWkCTsBVDVcjkGQCHvD6rDYfYPBrwDZiU=; b=kq8FlDiw3M2PZD+SpP1qRPEOkBAp7t30zzkWP+HqvJXv31/m/8fOHa/h9x5BTYcvg/ Mu6pSrE3cjesaat1zXDFWK5XN4YAM4GmefAVvwI47A03cRctoRxRd+B9k4OePMOMwpI4 dCsXk3npwCOM5M5HczuJSaSvfqri3YUJQbZFfi1fZYjVXFm3kaaDgLNSWjORCYOuRKTz 8j9cadBpxWuCMiwtGsDdM1N35wjZxgftLUqjQHmbNQziw3FEmbe1LVd756tMJRYRVoZO zp7014IE64ozZQHKMEbahhGH8Yq51DxjsIhfU26bcYMgEOOMBo3rnwti+rsKTlnrGJJg uBJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=m+ciRRszxYVWkCTsBVDVcjkGQCHvD6rDYfYPBrwDZiU=; b=Q0A0e0/ZKzQZ/H5hrD5g9mNCjKmF7FIj14vpYms9W/MwpurK7Sy0/i3NDmoAmSU8dZ UQ7Bj8HXqTSgv2ib0Z7/1nzHdZcNmsDa0RUORiwQ2Qm7r8MI0kH5i6FSmWzpCdonnOU3 n4ZRDED/cEBzLW5RZ1nU0gOR6ps19P+rMw5xRCcc1nFtKa/ypwV++ZrL0peC2BXsveR8 mhYnL4dI/F/nZfx7LiKZJwnZtC12kmBKQIncws1PHH0SnRpAni5CHlo5W9kgBo9lvsg/ F/X2Ry/1eewEVQdgp7IispIx/JKoN0kqStvXiMY5chwu8XSFnI5oCet73jwcLol2YfFv DCNA== X-Gm-Message-State: AGRZ1gLUZkX/sXBAWwZbyYMYjSi4nNUlrxJnU0R4E/ugZFnf/CzWrbkH SN1Igr32RIu+zTR5M4YT5lZvsZo= X-Google-Smtp-Source: AJdET5eyCbIg/q/yhfwIg5o4Au6IBxyAIveI+/sCkdZlVpTk3Cwm6eAiqrPF4uVDn8lweDHNhyk8dg== X-Received: by 2002:a9d:38d6:: with SMTP id k22mr4685380ote.77.1542309894944; Thu, 15 Nov 2018 11:24:54 -0800 (PST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Thu, 15 Nov 2018 13:24:38 -0600 Message-Id: <20181115192446.17187-5-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181115192446.17187-1-minyard@acm.org> References: <20181115192446.17187-1-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::341 Subject: [Qemu-devel] [PATCH v2 04/12] i2c: Add a length check to the SMBus write handling 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: Paolo Bonzini , Corey Minyard , "Dr . David Alan Gilbert" , minyard@acm.org, "Michael S . Tsirkin" 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" From: Corey Minyard Avoid an overflow. Signed-off-by: Corey Minyard Reviewed-by: Peter Maydell --- hw/i2c/smbus_slave.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hw/i2c/smbus_slave.c b/hw/i2c/smbus_slave.c index 83ca041b5d..fa988919d8 100644 --- a/hw/i2c/smbus_slave.c +++ b/hw/i2c/smbus_slave.c @@ -182,7 +182,11 @@ static int smbus_i2c_send(I2CSlave *s, uint8_t data) switch (dev->mode) { case SMBUS_WRITE_DATA: DPRINTF("Write data %02x\n", data); - dev->data_buf[dev->data_len++] =3D data; + if (dev->data_len >=3D sizeof(dev->data_buf)) { + BADF("Too many bytes sent\n"); + } else { + dev->data_buf[dev->data_len++] =3D data; + } break; =20 default: --=20 2.17.1