From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751429AbdGQM7U (ORCPT ); Mon, 17 Jul 2017 08:59:20 -0400 Received: from lb2-smtp-cloud2.xs4all.net ([194.109.24.25]:59320 "EHLO lb2-smtp-cloud2.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751358AbdGQM7S (ORCPT ); Mon, 17 Jul 2017 08:59:18 -0400 Subject: Re: [PATCH 14/22] [media] usbvision-i2c: fix format overflow warning To: Arnd Bergmann References: <20170714120720.906842-1-arnd@arndb.de> <20170714120720.906842-15-arnd@arndb.de> Cc: Linux Kernel Mailing List , Mauro Carvalho Chehab , Greg Kroah-Hartman , Linus Torvalds , Guenter Roeck , Andrew Morton , Networking , "David S . Miller" , "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi , the arch/x86 maintainers , Sakari Ailus , Linux Media Mailing List From: Hans Verkuil Message-ID: Date: Mon, 17 Jul 2017 14:59:15 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 17/07/17 14:57, Arnd Bergmann wrote: > On Mon, Jul 17, 2017 at 2:53 PM, Hans Verkuil wrote: >> On 14/07/17 14:07, Arnd Bergmann wrote: >>> gcc-7 notices that we copy a fixed length string into another >>> string of the same size, with additional characters: >>> >>> drivers/media/usb/usbvision/usbvision-i2c.c: In function 'usbvision_i2c_register': >>> drivers/media/usb/usbvision/usbvision-i2c.c:190:36: error: '%d' directive writing between 1 and 11 bytes into a region of size between 0 and 47 [-Werror=format-overflow=] >>> sprintf(usbvision->i2c_adap.name, "%s-%d-%s", i2c_adap_template.name, >>> ^~~~~~~~~~ >>> drivers/media/usb/usbvision/usbvision-i2c.c:190:2: note: 'sprintf' output between 4 and 76 bytes into a destination of size 48 >>> >>> We know this is fine as the template name is always "usbvision", so >>> we can easily avoid the warning by using this as the format string >>> directly. >> >> Hmm, how about replacing sprintf by snprintf? That feels a lot safer (this is very >> old code, it's not surprising it is still using sprintf). > > With snprintf(), you will still get a -Wformat-truncation warning. One > of my patches > disables that warning by default, but Mauro likes build-testing with > "make W=1", so > it would still show up then. > > However, we can do both: replace the string and use snprintf(). Yes please! Regards, Hans