From patchwork Mon Dec 3 12:52:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 152697 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6773442ljp; Mon, 3 Dec 2018 04:53:47 -0800 (PST) X-Google-Smtp-Source: AFSGD/Uwgroa7cfpPNLAz4t/ceYIltBM5IF37Uu0zSMnkhhIy++UUbwhW+bM2aYGT27OXkxh/2Dd X-Received: by 2002:a0c:d124:: with SMTP id a33mr15358180qvh.19.1543841627352; Mon, 03 Dec 2018 04:53:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543841627; cv=none; d=google.com; s=arc-20160816; b=R/rzhN4QJRcPpp4WpiXiGYMI30tZ10ll75gFcA2rM9TDXsn8/P3Du+C6nThIXb7z13 bNTsEgx/0g890D03dnsFSMDsjM4CPy0iyHrSsqx3RkwYnH7ZVHy2H0u3P9KC2NHsj1E0 liDibCvATC+34thMF2JpqMKAHfZgtcyP7oq3ep71DrBeSR+yBGTEVCVIn9Fp8nMS869s DJfnrh0GUzefW1GH2FuOmmEH3GeJPKVRNSJIkXy9r95PO5LxWkquk8W32KRnaPYIQZBa kBRMxpovLvq3Bri10/TWT0p4+4XaEEcko/zPdMVKz69FQnCW3zFXJ/42WcI64NrZi2r5 q4rg== 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 :content-transfer-encoding:mime-version:message-id:date:to:from :dkim-signature; bh=fRu7DuiyEfqeJ29TIA3hlqvaTzSLu/is23oXEg4Bvuc=; b=BUjBVWtG34bcyKX21zW8jTr+4Pe/cxdTlBd5buNFSmf8qrhUUzS4+MyG4rpDqNUVAO RaCmjA61BJjF/8JJ2Who9dOe5+R6s+6ZazsnRIrc+oqHLfNwUghmyB1hahh0f1MdRDoF bHHip7UiMo/ZE4Y5G1Kkmi8IWm7I5lifpJmgIpUbLFPnhrh1NHdlS+lKQmJC1nmR253u 8UDpsZwXvbWQ9l8O1ELBzJSiSsyBXSdidEk5ZsAAl1/CeDIWjN1XfS0WaLzp4xrV7nl0 MdK0vfdP3Y3PZ396WcoqsDxeuE9ycDwnKcRO+LchtbwX7m6bQ+HBDFLIKnPL4woM3aoZ VjxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=H62lQNhR; 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 d45si1206852qte.191.2018.12.03.04.53.47 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 03 Dec 2018 04:53:47 -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=H62lQNhR; 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]:48247 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gTnjO-0006os-NT for patch@linaro.org; Mon, 03 Dec 2018 07:53:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49755) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gTnj4-0006nI-7A for qemu-devel@nongnu.org; Mon, 03 Dec 2018 07:53:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gTnix-00089d-M4 for qemu-devel@nongnu.org; Mon, 03 Dec 2018 07:53:26 -0500 Received: from mail-oi1-x244.google.com ([2607:f8b0:4864:20::244]:33534) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gTnix-00088X-C6; Mon, 03 Dec 2018 07:53:19 -0500 Received: by mail-oi1-x244.google.com with SMTP id c206so10799059oib.0; Mon, 03 Dec 2018 04:53:18 -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:mime-version :content-transfer-encoding; bh=fRu7DuiyEfqeJ29TIA3hlqvaTzSLu/is23oXEg4Bvuc=; b=H62lQNhRAvVoBs3w0KG44yeWkEoWPrEh0r4bLY1imrurGV4QSxhomnpc7yrIkrElAa Q+XY+R7lGhhvZs+EOzvKNMVrKi48lp2vUu+H8SPY8lZ7XCyelceUbHh/X2F/KbsO5jQL CAESUFJzcNyPtPacX96C4OPkiDfcPPKOCgv2ohEs8t08JmuAZaCG/QzuB3YGTI61gfxp F9BAMf+AaUAWULPHvxr2OIAK2Fx9dD+WCz4HhrilmOs0TdKhlmj4z8xNLb8iDflxOcws qTBLH/PlyiOWQ7v51S6zE0RpBl5gBAW0UM8lzfZaPWAnQyDlOlyRmF1CS6XPg3q+5tFi BBKw== 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 :mime-version:content-transfer-encoding; bh=fRu7DuiyEfqeJ29TIA3hlqvaTzSLu/is23oXEg4Bvuc=; b=nZPoxUp6bVjmJL+Kvz5zHvTcFdnFOlnIub/4J77efyYIo/kXt5F4QLyll2sNJEy72p AuKMl68Z8JIsnbskTQTt0Pvs+fuJu6AL1/QorgByHn8qCQDAdsl5DDhQunIeu/JsikoO mp1/VNWCqvShZkmbMLgO24+28yCK+km4XD613W8v/nnVQpuN9zRsLYCwssjmEigH9ioh JC3v7iYjxsjXOgsE7oVTAuJbW/QWyHiubAXuKwjbV9XA8a7TlbW72r0uBcRYhvGFGtiP hLa3R5WDsR22gF2o/9BlU8UvxMwTkWhPNJODfgPJjkY5ryx+0yCdj2XFoQ1pnO11Op3S jHlg== X-Gm-Message-State: AA+aEWYJ9ERUPGijzVjeFoAcVETojgJsj7VbCbNYXxExiyBEoCd4EYuR vAvN08aWSHcxwDhW8/5TMQ== X-Received: by 2002:aca:5a88:: with SMTP id o130mr10335287oib.275.1543841597443; Mon, 03 Dec 2018 04:53:17 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id t2sm6109572otl.4.2018.12.03.04.53.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Dec 2018 04:53:16 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 3E1923A3; Mon, 3 Dec 2018 06:53:15 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 89E4330054B; Mon, 3 Dec 2018 06:53:14 -0600 (CST) From: minyard@acm.org To: Peter Maydell , qemu-devel@nongnu.org Date: Mon, 3 Dec 2018 06:52:50 -0600 Message-Id: <20181203125250.11195-1-minyard@acm.org> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::244 Subject: [Qemu-devel] [PATCH] 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: Corey Minyard , Corey Minyard , "Michael S . Tsirkin" , "Dr . David Alan Gilbert" , QEMU Stable , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?b?w6k=?= 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 Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Cc: QEMU Stable --- hw/i2c/smbus.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/hw/i2c/smbus.c b/hw/i2c/smbus.c index 6ff77c582f..30028bfcc2 100644 --- a/hw/i2c/smbus.c +++ b/hw/i2c/smbus.c @@ -193,7 +193,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: BADF("Unexpected write in state %d\n", dev->mode);