From patchwork Fri Jul 14 12:07:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 107792 Delivered-To: patch@linaro.org Received: by 10.182.45.195 with SMTP id p3csp891662obm; Fri, 14 Jul 2017 05:12:39 -0700 (PDT) X-Received: by 10.98.200.208 with SMTP id i77mr4920211pfk.54.1500034359550; Fri, 14 Jul 2017 05:12:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500034359; cv=none; d=google.com; s=arc-20160816; b=gj28Gy40GyUFn2y/4m2Wu3DoLxeU3zNcQOMuQdgJ1aymhl/odiqH8fgeofFAvEBPoL h+lSUtu1jzr6tSsgEBun0cuqdMH0LZZ+bdkDRfGO1eIaUqGVq10UT6bJXb66TKrR05Vw baa8y6tjA/MrQMIVFMDkjo60hQCh029apqRa6M3zjN99J046lf5QBBcz5FpYm1fIqO1T FqFXANeZWVKQLd+HDGpVVwhpR50sYuN69uxoVcmdrPA9Oqoe4zstlkVi1TQcnlrErIIa NRf9mczbPp/1Lj+Inl3Z6Vi3Q82UKpCb3itEjCyRgVk954bIULNSJ494nIdJU/L5lAgp HV7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=5K44f/lnO3maSXI8PEu89Or0t/0pl3Sc2x0X72MgaEc=; b=nCsM+m+2yPlttANPW5vpIrsVtX0Nt09DXPdumWNtlS9WGycRakEkDkWN0bIE1YJT8C 4ZQkvToN7fiyy28fe9twJlUQH7uYh6veqH7ZNI346tk3WCQI9Kg/ONBgyTZUF55Ub4lW otKPsSMneR6LW06pk8lDhj4Hb2qNC9WpnF9VlSwFuTrIhFBRe3HD1F/jtLSo9KpSMWeu UAloZGph7B8R3FiwDAjcOp9EggxIVJU3faEvwz3/kLzRePOgWMRrTMVfAw77fgeM57pe nrqJY0szSIcJMP5ghSFLcUpZ7+kKgFU6HEHf09ROXI+jWTdw/V38DQQyVZ9CrdnFqjXV E/5w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m25si3479214pge.248.2017.07.14.05.12.39; Fri, 14 Jul 2017 05:12:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932134AbdGNMMe (ORCPT + 25 others); Fri, 14 Jul 2017 08:12:34 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:52163 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753577AbdGNMMa (ORCPT ); Fri, 14 Jul 2017 08:12:30 -0400 Received: from wuerfel.lan ([5.56.224.194]) by mrelayeu.kundenserver.de (mreue104 [212.227.15.145]) with ESMTPA (Nemesis) id 0M0zHj-1dnFfx3msJ-00v5z6; Fri, 14 Jul 2017 14:11:15 +0200 From: Arnd Bergmann To: linux-kernel@vger.kernel.org, Henrik Rydberg , Jean Delvare , Guenter Roeck Cc: Greg Kroah-Hartman , Linus Torvalds , akpm@linux-foundation.org, netdev@vger.kernel.org, "David S . Miller" , "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, x86@kernel.org, Arnd Bergmann , linux-hwmon@vger.kernel.org Subject: [PATCH 15/22] hwmon: applesmc: fix format string overflow Date: Fri, 14 Jul 2017 14:07:07 +0200 Message-Id: <20170714120720.906842-16-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170714120720.906842-1-arnd@arndb.de> References: <20170714120720.906842-1-arnd@arndb.de> X-Provags-ID: V03:K0:EVXxi8Zcg44DGLm90NBmJx+6uvH9r38SU5y2VcZGqs49u2RA/tf eIlhqCGffZNYfX1/j1qJuqmX62baOD/34u30oyYebqM06MNayQ1JOxdHXXxg0EyYJLNnbo3 pmxhBkLX+GMX3faGLNuLobXDEvg8x6jsIxad0kJZs1McPdk267KGJbT2ediXlZM7YFf7HS4 vLizQGCpdMNns/0sFawxg== X-UI-Out-Filterresults: notjunk:1; V01:K0:sP0UG4dlMQE=:akFpSTCBf8Zvk1xK3jYi+l /o3D8jhjGvcq/4C4qbUo4tJOn9nKfbYm+mWY+Xq1i8KFvT9/jjk12I+4vT0yzvl5BjSmjmMtn wu+0WL6Ipid15zCitDnlu97YD4C31KhBaiFIzuSlJKChIpS6oOFTEy2p7zCT8mIOKjGZXM5JT gPFQKscGpCoVSAiB4qpexuIvoLNvD3VblzxrrBT9I2ThL+1SrCho6vCxMTadwAWlReDvwTYtA G1Iiz1vCr0Q8j0QRM26Nh4yJM0fDsPNYJtKgV2LFSEczS6SO7/l0KAIyzMDUxLpNy6H9Gv4Km PNbe95gWtd6vpVNy+Pr7UGepT/367QPSLEmPP5E1jzDB7f6w5dlUBGyvqhHnBwszO2y61/i8r P5MfzU7q2fgM+tRBS1wVIOA/UEZu0BnNZQXZP+EkEKxOFkd9pRe+dzHTMbB79SZRhTJ7sWkCl pvnsYfu2WJihG4dnhjEwyRsWBg/edm+BmekLvptlZKwDw5ENzjmz7VnRwNpwowUUsmRGXEBjv c012BP9ujV3+lpptOEZWo11MCqnpimsrE/EsnDigxlkPL406db9TYePqxK4pNpn36Qok3fGC6 HQo4ElkZsMaEykbuMJTQ1qgqDwkOdIIwAJqJCiT2pUSb6MOAAmdR62tQ5sqXnoYkMu5n8y2oI y09CZoBuiKKHbYM2jTfSSn4HYzh1WMa0IeALK6QWl+rNJumDN6VK8lUNLOURF1qVKFz8zL7KQ +Y0IbQxerhLPETmRCG3EmeKac0tXFAhV2hfjdw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org gcc-7 warns that the key might exceed five bytes for lage index values: drivers/hwmon/applesmc.c: In function 'applesmc_show_fan_position': drivers/hwmon/applesmc.c:906:18: error: '%d' directive writing between 1 and 5 bytes into a region of size 4 [-Werror=format-overflow=] sprintf(newkey, FAN_ID_FMT, to_index(attr)); ^~~~~~~ drivers/hwmon/applesmc.c:906:18: note: directive argument in the range [0, 65535] drivers/hwmon/applesmc.c:906:2: note: 'sprintf' output between 5 and 9 bytes into a destination of size 5 As the key is required to be four characters plus trailing zero, we know that the index has to be small here. I'm using snprintf() to avoid the warning. This would truncate the string instead of overflowing. Signed-off-by: Arnd Bergmann --- drivers/hwmon/applesmc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.9.0 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c index 0af7fd311979..515163b9a89f 100644 --- a/drivers/hwmon/applesmc.c +++ b/drivers/hwmon/applesmc.c @@ -903,7 +903,7 @@ static ssize_t applesmc_show_fan_position(struct device *dev, char newkey[5]; u8 buffer[17]; - sprintf(newkey, FAN_ID_FMT, to_index(attr)); + snprintf(newkey, sizeof(newkey), FAN_ID_FMT, to_index(attr)); ret = applesmc_read_key(newkey, buffer, 16); buffer[16] = 0;