From patchwork Mon Nov 26 20:04:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 10699133 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 93E9615A7 for ; Mon, 26 Nov 2018 20:27:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 815C42A343 for ; Mon, 26 Nov 2018 20:27:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6FD442A350; Mon, 26 Nov 2018 20:27:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 051C92A343 for ; Mon, 26 Nov 2018 20:27:14 +0000 (UTC) Received: from localhost ([::1]:38673 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gRNTN-0004oT-1F for patchwork-qemu-devel@patchwork.kernel.org; Mon, 26 Nov 2018 15:27:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53714) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gRN81-0001lL-Dw for qemu-devel@nongnu.org; Mon, 26 Nov 2018 15:05:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gRN7y-0001Kw-Ef for qemu-devel@nongnu.org; Mon, 26 Nov 2018 15:05:09 -0500 Received: from mail-oi1-x241.google.com ([2607:f8b0:4864:20::241]:47029) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gRN7x-0001Gq-RB for qemu-devel@nongnu.org; Mon, 26 Nov 2018 15:05:06 -0500 Received: by mail-oi1-x241.google.com with SMTP id x202so17049993oif.13 for ; Mon, 26 Nov 2018 12:04:54 -0800 (PST) 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=QuWkseNSkDxwCm/6G4Rne617fRLHLL/I95YrixkuQNk=; b=r2dl5ox0vP9/2VDYy9C9Lvjz6QiBMy4dxRxM+RLU7ck+Ws9/v5Z6sRuWsQ0X6N0GkL OiU3mD+5dCWETaZhC1+pFtZztiedzVbPPDIMI0CnUh6PQwMf2dF5zxQYvz3HQ7BAeb69 Oe685q/Nkrhu14b7IxF8ODQfABpFox2Bk9qO3l98SgaY7Mwm4fDkhgRznWAiSAbBFwJz Jb0ehcUiyk+ZG5ZZ+qlhSBjnawrlkmJTZs18wnmKgbK5jPPqGQpHaWj7A6GvJtxQelYW b+/pa7XoXgLeiy8vzm2zzltDY3EJFcxoH7hbDSGV/rxXg7d94vEalMu++5gYcnxqQETw Oo2Q== 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=QuWkseNSkDxwCm/6G4Rne617fRLHLL/I95YrixkuQNk=; b=bCrEbwjplvSrcn2tF9qnodP/yNU4EXVdMl9HsAgzmrJzSO1o05mFJj5opIyV1xnm0J 4nhQV57cQKrN38UDc7DsQ55HWkgIbgGX459TmV20oOFe8xqgaY0J3S2frcKW8wDXu+x0 nS1X2TOTnMwsotwCqM3ucMUjlrkve+JkjoT0fcYXudfzkzXRxpYWvdWG7nCEGwZcKtmd 7AduvosN88/qhmEncFRNFb8CQ/A58IWPbcbbK5McmfCc9KQOy+isBnLaIoBjd9lRSqWY xEJJhMLFQCb6ky3gRZFq1qCmo6jXbQkKoYNAvKtx4KVLdGPrWYIwiTPbyAZWPyofx7GP j5Xg== X-Gm-Message-State: AA+aEWZIkJ4jq3KaNHSCxT5DkB3zEUJm0eInGH65bUQqW260n0d26Gwc 19mkoMERrTmt4VmI9oTpqWtGfaQ= X-Google-Smtp-Source: AFSGD/XQS8zO+YeCFAGlem7rl3Tr3BiJt4XpFY84JGT8PZegEPBpgADnElw3yvSwLtVsCA6+ksMXkA== X-Received: by 2002:aca:5c4:: with SMTP id 187mr2184971oif.20.1543262694052; Mon, 26 Nov 2018 12:04:54 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id 30sm678037otr.64.2018.11.26.12.04.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Nov 2018 12:04:52 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 7939E1075; Mon, 26 Nov 2018 14:04:48 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 5EBEE301467; Mon, 26 Nov 2018 14:04:46 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, "Dr . David Alan Gilbert" , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Peter Maydell Date: Mon, 26 Nov 2018 14:04:25 -0600 Message-Id: <20181126200435.23408-7-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181126200435.23408-1-minyard@acm.org> References: <20181126200435.23408-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::241 Subject: [Qemu-devel] [PATCH v3 06/16] 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 , Corey Minyard , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Corey Minyard Avoid an overflow. Signed-off-by: Corey Minyard Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé --- 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 70ff29c095..d03f714608 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++] = data; + if (dev->data_len >= sizeof(dev->data_buf)) { + BADF("Too many bytes sent\n"); + } else { + dev->data_buf[dev->data_len++] = data; + } break; default: