From patchwork Fri Jul 14 12:07:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 107787 Delivered-To: patch@linaro.org Received: by 10.182.45.195 with SMTP id p3csp889999obm; Fri, 14 Jul 2017 05:11:18 -0700 (PDT) X-Received: by 10.84.217.204 with SMTP id d12mr16204843plj.208.1500034278445; Fri, 14 Jul 2017 05:11:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500034278; cv=none; d=google.com; s=arc-20160816; b=lDS94HWMKB/VNL8BQdXd57MBL9PIXywdkzbEvxPdmgFap+ShgWkw6vrSgmgx4tBQdb uXvEVHzzCkfIcMogq5TKLOMHANPFVDvGZKn/gGpFGxjXBAYMXTFzwnKsUQIfA6iChazu DcpoVl6Tu9i1e/f7uiNSMnCd9KzKKII7XGJZI9pBcI2INEDEyH6BoGbBIponLXiknYrr brxn4GA/yJstHlQFhSX3cFMU71cJF7X8Zaf+FcMkWWbQjqOzsopGxtLVz0br28Dkq2nK Zms0/6bKRYULSgPXBh1CN1V9ySGZzAI2FvWoqP7cnA2jezISlw9v5l6V3bsdil1pwJes BFFA== 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=+eLLZjQTtghc2sbBTjA6ie1j7zCTVGKOuXgHcM77YW8=; b=LftVGPhEopXQ9RnYSxt/V9Gsn44MYQ1haxYri/mic4WhBVLCyL6rXNUk+XWmzjzlOK 9mqVei5KBBdWP3AOub48GTf6BoikaGKBozuxDrX18TWGTHl67lvF+EG7zs9MyHLD5SAj fy2D5NqqBYnVmZqBvoCVI2fvJDaj6K6Rm09JkNbo7QMdMxwDZCfzwUf+ELl5HNU/7QD3 bySuV9CfS8aohbbpTMcRZS5ZPtE4FMCv5g1ZMd7Ler9VNMhkdh+Rc2Nx3lVJPxT8F3CG Vu3myJ08xEGQmDgsvqgEdad0HavT1mGYLgf4c4ZgTff7TuBlkPXALCduYT+8h/Ic0ZL/ 43NQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-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 n19si6404893pfb.298.2017.07.14.05.11.18; Fri, 14 Jul 2017 05:11:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of netdev-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 netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754177AbdGNMLF (ORCPT + 6 others); Fri, 14 Jul 2017 08:11:05 -0400 Received: from mout.kundenserver.de ([217.72.192.75]:50878 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753787AbdGNMLC (ORCPT ); Fri, 14 Jul 2017 08:11:02 -0400 Received: from wuerfel.lan ([5.56.224.194]) by mrelayeu.kundenserver.de (mreue104 [212.227.15.145]) with ESMTPA (Nemesis) id 0MKILu-1dXdZi0kgY-001lPF; Fri, 14 Jul 2017 14:09:48 +0200 From: Arnd Bergmann To: linux-kernel@vger.kernel.org, "David S. Miller" , Philippe Reynes , Arnd Bergmann Cc: Greg Kroah-Hartman , Linus Torvalds , Guenter Roeck , akpm@linux-foundation.org, netdev@vger.kernel.org, "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, x86@kernel.org, Eric Dumazet , stephen hemminger , Jarod Wilson Subject: [PATCH 09/22] net: niu: fix format string overflow warning: Date: Fri, 14 Jul 2017 14:07:01 +0200 Message-Id: <20170714120720.906842-10-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:o9DsCjMqhYPrSeaoG05YBsMDCy0Xl0FwinimcpuSeTEqWhwFEbR wy9XTgaDd2Xa7ks6XmURLR10oGK+eTKv6Z+A/WT7mGlabQmqZN0XBotAbqzfV4qFOZlIaig LcbdKVjjWsNTI7Ibv5ui0RX0HMWeRw6Maa+BmM0oDK9FpNYtEb2Uv1ZadJsR0uLRmL4qhq3 ZQShAPcStXaYNdjP/27Sw== X-UI-Out-Filterresults: notjunk:1; V01:K0:PwoUYWXciTY=:6Vh/sLq2a9c67bQvlnw2cI IVTOl1SDgIvBXDEU7b/gm9Vn/v4mDYJqIm6Nbs67nWwz3GMZ+PAJ32DlK1N9dTzj4gZrtfLXZ F7+AFiom2tdDlFyCNDV5DrK+BMpevI+mj+fdvEsQi/vLeVu+V2ldpSxMWZNHtueDTgfz8IagG W2xk4mP/ntP1u2ttBVIJN9Sy6IeZh5312lKXFULryMw8sp42yz+ptgwwVW4zHE+V0AptRAgfF wfhJtc3y5cyUq2IgWXRwQZkQEjWu25kzD3cuHpJN7JOmXYod1lfrIKyiV/PRCGcA2zsvOcSI+ Zau3nSN3Gw8pjXJvsC71lxenJNHjjVGWHKOjzP+S53aZ2obnbutK+Ud/6qvb7c+CbP6C7tT/+ ehG4v+poR+xMEMnWlA2UsHrg+MKwSZ7ZXhy+u0MOzcYUverUx0YTN0hVvN1nDAN0rKuK01hln zwRdT9Zpj5PSk1iBFwkxedciziXyFpyN3asEHiBdJrN2tJJhpWe+Cyt476wL0l1znOdY/h/Vs cH3JS9qIqnMmuKi3aDHlduVClDk2kAeeK15bY5L0yDYqd+IFYBeFMQscyA4nZc58uZcDCeLg0 B6flwpmq6DImYbS8SIYMddVhfH9sbrvbMhwEGOy9Y8fcq5gzR2sVRCOkYWaeqUzsIJnOGDwnX v1pHqgtwx5B5wYDVhA4l7c66oJLkAKLrAnE3J38ck9mC8tAJ8wVZQHchmXy8W3/UQghRLs2u6 qdoUQzXHHWWbPDQN2HyWnf4sQ7PvnXGD2WeDqA== Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org We get a warning for the port_name string that might be longer than six characters if we had more than 10 ports: drivers/net/ethernet/sun/niu.c: In function 'niu_put_parent': drivers/net/ethernet/sun/niu.c:9563:21: error: '%d' directive writing between 1 and 3 bytes into a region of size 2 [-Werror=format-overflow=] sprintf(port_name, "port%d", port); ^~~~~~~~ drivers/net/ethernet/sun/niu.c:9563:21: note: directive argument in the range [0, 255] drivers/net/ethernet/sun/niu.c:9563:2: note: 'sprintf' output between 6 and 8 bytes into a destination of size 6 sprintf(port_name, "port%d", port); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/net/ethernet/sun/niu.c: In function 'niu_pci_init_one': drivers/net/ethernet/sun/niu.c:9538:22: error: '%d' directive writing between 1 and 3 bytes into a region of size 2 [-Werror=format-overflow=] sprintf(port_name, "port%d", port); ^~~~~~~~ drivers/net/ethernet/sun/niu.c:9538:22: note: directive argument in the range [0, 255] drivers/net/ethernet/sun/niu.c:9538:3: note: 'sprintf' output between 6 and 8 bytes into a destination of size 6 While we know that the port number is small, there is no harm in making the format string two bytes longer to avoid the warning. Signed-off-by: Arnd Bergmann --- drivers/net/ethernet/sun/niu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.9.0 diff --git a/drivers/net/ethernet/sun/niu.c b/drivers/net/ethernet/sun/niu.c index 46cb7f8955a2..4bb04aaf9650 100644 --- a/drivers/net/ethernet/sun/niu.c +++ b/drivers/net/ethernet/sun/niu.c @@ -9532,7 +9532,7 @@ static struct niu_parent *niu_get_parent(struct niu *np, p = niu_new_parent(np, id, ptype); if (p) { - char port_name[6]; + char port_name[8]; int err; sprintf(port_name, "port%d", port); @@ -9553,7 +9553,7 @@ static void niu_put_parent(struct niu *np) { struct niu_parent *p = np->parent; u8 port = np->port; - char port_name[6]; + char port_name[8]; BUG_ON(!p || p->ports[port] != np); From patchwork Fri Jul 14 12:07:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 107796 Delivered-To: patch@linaro.org Received: by 10.182.45.195 with SMTP id p3csp893459obm; Fri, 14 Jul 2017 05:14:08 -0700 (PDT) X-Received: by 10.84.135.101 with SMTP id 92mr15457530pli.56.1500034448069; Fri, 14 Jul 2017 05:14:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500034448; cv=none; d=google.com; s=arc-20160816; b=Ai3W7y4oBAMEqn2dT0S0JH1jecHqJVwo21XKkUATRWUZ7cscx5meoGrPubKEu8UaX6 4GkMa9ptIvFfP90ANKN9fgsHSX++G5s9MedzuzqFgCtDPfmyOXjrnPpI4W6U8D4D92IS BVaJUwEgYnsqme9nADTrLqO4Rqbrk8rv9e9ex5axNnfeaF+5fwgM25x/AurdNCKHymRv YbLW0sjAM6gN008MG0KkFG6i/ZdqrUk13vQD8u2l7VhKPS6aPCgHlcuIqUx7Yh4H6v6o GOK6ScC06EziZEAIBDC5qAx39r9Kp/BUZ6vRZNB1zUIECUzX/Ak8DqBuTjFjVzsVL6F9 fFaQ== 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=Vm4LC0CRtLO75ra8CqT88qGlEk+5mJHEC+59bfd8jBw=; b=dukeLBqwabN+Lj1m3XwZFidWmNmnqlQYmigu9Yrz2MbQy/4Mc2fRhhmJUior0kkZeh aRGszJd4zp+B77+1cP08RWoAUN/gVOJ86VbKpi/JpLlL5Q6FZxu2EA8D07t77THUaPQL OV5zc3JXO87V+oY5VlpFzBJvXa3BeEcp2xDGqOmZEZECUZ734LGE0BcKLZBKgZUZLRNP aAEpxPFBj+PQLDaWEJX3xW9iKWIv8y+K0SzjiAGFAkNmsTgI0dDZ5qJqlFe5QoEDCMU2 MbKpmBxrkNhoBkAHBTfxg1kziMwxGVDjv0rVZHf1zxKs40OPn3iFXDuQW3Fj6SzfvHAH uTfw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-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 e8si6351241plk.206.2017.07.14.05.14.07; Fri, 14 Jul 2017 05:14:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of netdev-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 netdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932117AbdGNMNx (ORCPT + 6 others); Fri, 14 Jul 2017 08:13:53 -0400 Received: from mout.kundenserver.de ([217.72.192.75]:52184 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932070AbdGNMNv (ORCPT ); Fri, 14 Jul 2017 08:13:51 -0400 Received: from wuerfel.lan ([5.56.224.194]) by mrelayeu.kundenserver.de (mreue104 [212.227.15.145]) with ESMTPA (Nemesis) id 0MD8ge-1dQRXi3lZU-00GaK3; Fri, 14 Jul 2017 14:12:27 +0200 From: Arnd Bergmann To: linux-kernel@vger.kernel.org, Jens Axboe , Andrew Morton Cc: Greg Kroah-Hartman , Linus Torvalds , Guenter Roeck , netdev@vger.kernel.org, "David S . Miller" , "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, x86@kernel.org, Arnd Bergmann , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Subject: [PATCH 19/22] block: DAC960: shut up format-overflow warning Date: Fri, 14 Jul 2017 14:07:11 +0200 Message-Id: <20170714120720.906842-20-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:yO6NB2DdAGaCBpQ31HW3l3rBybLTHqjY+Iz1Xo3MD+sF4BgKa8t uJ68961LZWwvbhO9pDqBSbz6TSIank139cOsEqibPqjaTFpG75kN5iCVwFAdwfyHPsQFxeG TQ4bo9sZPozJK1KEr72W6CmD3r4VyimmZiHwUPTmNCX8rdFE5Z7tf6uImnjl6qGNBpKQ8He wb1zvBHGOOHDmufjh3UGQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:mkrUUV/yY7s=:3UWxy19ABTYinIokGxw2qe qFlokVBP6pCJyb3jLq23ZUgn+Agb0VtC7doZGniWz6bNAtUTuqfxml64NLBxqrYAKxSXolpVK 1tNsg3HL33htklpxezKFkKKb91XeV+NYnr3LEFbxI9S5WJK5omktF9GjgqLWFLCWdg5pk/STE SoSgwOWwTHPIEmR14vOoX6PDWzxncDeXqTB1BoxB5Xyl+ruBqEOpOZclYRc/P5BvNUhBTyt8d ewb21iDlyJe/FhMyNARGgpf6IEKjPpynAw7Per71U/fX56tEHPm37kQroD/hgnb2znlCZMTGX 71zjFTilPEiHKB3yUgg4QNhZLwhVIycongu/hoERxE5w7Gl8kXLRuDmuaQuAGqGtlYcmd+u4a ncQ2nCX6undfXLd7+GX2AHXSkKhZheua5i7HkkX2QgXmoApLyFZUi2JldXFIDpams0u29rMfp keT7BBwU4cLwN4qok1cl/pPXzMPc1vfvFd0Fi0+v+OVhc76afTIh/OUFSxf2O8qK/XRXME5kk jX5/26p5p5gRJMzgwBL7HW7vDd2hmdfrUAZMoQyVtfJ/4mBz1cTkptQ9t83xdVfNYnntvPdUN B3Yrrtj8pKJjBnKGgm/B71J2UykTAcq4YlnoQd+VtV8v9/IH5WTgK2iOt3aoGU1WW55jEmi+B xn4gMO4k+J1rl7YPzmFNF/TXvGUQDRTkYNiXFDSQMaB1PZeJG4i2yeao12ekQtrq7phfSC4ac gURyxXOYd2vOFPv342j/RA4Zz3HFKxJkDjNaYg== Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org gcc-7 points out that a large controller number would overflow the string length for the procfs name and the firmware version string: drivers/block/DAC960.c: In function 'DAC960_Probe': drivers/block/DAC960.c:6591:38: warning: 'sprintf' may write a terminating nul past the end of the destination [-Wformat-overflow=] drivers/block/DAC960.c: In function 'DAC960_V1_ReadControllerConfiguration': drivers/block/DAC960.c:1681:40: error: '%02d' directive writing between 2 and 3 bytes into a region of size between 2 and 5 [-Werror=format-overflow=] drivers/block/DAC960.c:1681:40: note: directive argument in the range [0, 255] drivers/block/DAC960.c:1681:3: note: 'sprintf' output between 10 and 14 bytes into a destination of size 12 Both of these seem appropriately sized, and using snprintf() instead of sprintf() improves this by ensuring that even incorrect data won't cause undefined behavior here. Signed-off-by: Arnd Bergmann --- drivers/block/DAC960.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) -- 2.9.0 diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c index 245a879b036e..255591ab3716 100644 --- a/drivers/block/DAC960.c +++ b/drivers/block/DAC960.c @@ -1678,9 +1678,12 @@ static bool DAC960_V1_ReadControllerConfiguration(DAC960_Controller_T Enquiry2->FirmwareID.FirmwareType = '0'; Enquiry2->FirmwareID.TurnID = 0; } - sprintf(Controller->FirmwareVersion, "%d.%02d-%c-%02d", - Enquiry2->FirmwareID.MajorVersion, Enquiry2->FirmwareID.MinorVersion, - Enquiry2->FirmwareID.FirmwareType, Enquiry2->FirmwareID.TurnID); + snprintf(Controller->FirmwareVersion, sizeof(Controller->FirmwareVersion), + "%d.%02d-%c-%02d", + Enquiry2->FirmwareID.MajorVersion, + Enquiry2->FirmwareID.MinorVersion, + Enquiry2->FirmwareID.FirmwareType, + Enquiry2->FirmwareID.TurnID); if (!((Controller->FirmwareVersion[0] == '5' && strcmp(Controller->FirmwareVersion, "5.06") >= 0) || (Controller->FirmwareVersion[0] == '4' && @@ -6588,7 +6591,8 @@ static void DAC960_CreateProcEntries(DAC960_Controller_T *Controller) &dac960_proc_fops); } - sprintf(Controller->ControllerName, "c%d", Controller->ControllerNumber); + snprintf(Controller->ControllerName, sizeof(Controller->ControllerName), + "c%d", Controller->ControllerNumber); ControllerProcEntry = proc_mkdir(Controller->ControllerName, DAC960_ProcDirectoryEntry); proc_create_data("initial_status", 0, ControllerProcEntry, &dac960_initial_status_proc_fops, Controller);