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: 10709493 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 DDC5413BF for ; Mon, 3 Dec 2018 12:54:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 757C12AD21 for ; Mon, 3 Dec 2018 12:54:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6768F2B134; Mon, 3 Dec 2018 12:54:37 +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 A9C7F2AD21 for ; Mon, 3 Dec 2018 12:54:31 +0000 (UTC) Received: from localhost ([::1]:48253 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gTnk5-0007iW-PH for patchwork-qemu-devel@patchwork.kernel.org; Mon, 03 Dec 2018 07:54:29 -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-Google-Smtp-Source: AFSGD/XwC1FUiSs9rN5i2f4eev7uksSGIyEIZ1dtXwguUNtkUDYkAx26LbrYKQk0lIXBC/0huETihQ== 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=C3=A9?= 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é Cc: QEMU Stable --- hw/i2c/smbus.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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);