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: 152073 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp332352ljp; Mon, 26 Nov 2018 12:28:22 -0800 (PST) X-Google-Smtp-Source: AJdET5cb+98rJ0yWR1qmBmWwwlBfkOR1ws2qG+iIEi5g43O+D3kESLT2bJjGLCjhNAJSbjkaoF+m X-Received: by 2002:a81:b719:: with SMTP id v25mr31687089ywh.131.1543264102403; Mon, 26 Nov 2018 12:28:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543264102; cv=none; d=google.com; s=arc-20160816; b=kD1Tmm+Uu9Bp+jEiLsh+yO6kJrV+GD9Aa7/H2PDN3h4CoH0hHDcTtGGbtjzwl8Wesw oJnHr+AfgAG3hb+S/nNtlp1BjceNV1XNvGAPfIn/sOF0pF32LU+53bWS/omw9eDY7iNV Y1zadscpGtGqrgxCzTOLH85OkSk8+YfxOhFpoJxjvaWGaibIFgRA8ZbqKWtpxshqcE5V jMyrGTaIEzU+0Pze7Z9ZTDYP4zcWiGrFyZFqj3BjRkAyee20SnQOTSA9NZgI7/9gU9/Y iLMXp/RaVcmOTkqtS2Lme7zQmofxQflQrr7peroU6kTVyTcZMyN2Lz1SMv0gDs/42l/L RSrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=QuWkseNSkDxwCm/6G4Rne617fRLHLL/I95YrixkuQNk=; b=eL31asdw/YzZz164LWKWUnFOkKoj54sLatEqK8xGtCjIDMHkKR/p7Qdj0vXMl0lw6g A7Ko4qfLiLNdq2eRbrmE8u0uwOog9djUF14B0Cf4VAGN3FJSCo5XvC3iCTy0zBjYPcLA ob39qKjVshlfkO9agJz0ytf9A3PPwzSvXZZSK6YywKMJbD89PK9VRDO3P4knCv2y3Ryg wZJC0KAygVK47377oNsqBt9XNCT6xKO0OBHxFWfejjPabJxNnjLQ2VKIE0KKDR2Taq5q 7GiRVaNENnhO2L9VS2/IMGS8y4/oUb9TuVPIURV4GQ5ktiMSOKShdhfVYean/y1tKbTR q9Mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=r2dl5ox0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id s186si1077679ywf.144.2018.11.26.12.28.22 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 26 Nov 2018 12:28:22 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=r2dl5ox0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:38673 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gRNUT-0004oT-Kz for patch@linaro.org; Mon, 26 Nov 2018 15:28:21 -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-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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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(-) -- 2.17.1 Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé 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: