From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64B63C433E2 for ; Fri, 28 Aug 2020 19:43:38 +0000 (UTC) Received: from isis.lip6.fr (isis.lip6.fr [132.227.60.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E6E332087D for ; Fri, 28 Aug 2020 19:43:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E6E332087D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=ACULAB.COM Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=cocci-bounces@systeme.lip6.fr Received: from systeme.lip6.fr (systeme.lip6.fr [132.227.104.7]) by isis.lip6.fr (8.15.2/8.15.2) with ESMTP id 07SJhD0l023125; Fri, 28 Aug 2020 21:43:13 +0200 (CEST) Received: from systeme.lip6.fr (systeme.lip6.fr [127.0.0.1]) by systeme.lip6.fr (Postfix) with ESMTP id 986967807; Fri, 28 Aug 2020 21:43:12 +0200 (CEST) Received: from isis.lip6.fr (isis.lip6.fr [132.227.60.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by systeme.lip6.fr (Postfix) with ESMTPS id D31E83C97 for ; Fri, 28 Aug 2020 00:03:24 +0200 (CEST) Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by isis.lip6.fr (8.15.2/8.15.2) with ESMTPS id 07RM3NPc024386 (version=TLSv1.2 cipher=DHE-RSA-AES256-SHA256 bits=256 verify=NO) for ; Fri, 28 Aug 2020 00:03:23 +0200 (CEST) Received: from AcuMS.aculab.com (156.67.243.126 [156.67.243.126]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-59-OGrq4_s1M6OWOpSfz2k_Ug-1; Thu, 27 Aug 2020 23:03:21 +0100 X-MC-Unique: OGrq4_s1M6OWOpSfz2k_Ug-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) by AcuMS.aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Thu, 27 Aug 2020 23:03:20 +0100 Received: from AcuMS.Aculab.com ([fe80::43c:695e:880f:8750]) by AcuMS.aculab.com ([fe80::43c:695e:880f:8750%12]) with mapi id 15.00.1347.000; Thu, 27 Aug 2020 23:03:20 +0100 From: David Laight To: "'Joe Perches'" , Julia Lawall Thread-Topic: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs Thread-Index: AQHWfLDNatYqQRMSW0+Lm7S5UM8VU6lMgaZA Date: Thu, 27 Aug 2020 22:03:20 +0000 Message-ID: References: <20200824222322.22962-1-alex.dewar90@gmail.com> <48f2dc90-7852-eaf1-55d7-2c85cf954688@rasmusvillemoes.dk> <20200827071537.GA168593@kroah.com> <20200827131819.7rcl2f5js3hkoqj2@lenovo-laptop> <20200827144846.yauuttjaqtxaldxg@lenovo-laptop> <5d1dfb9b031130d4d20763ec621233a19d6a88a2.camel@perches.com> In-Reply-To: Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: aculab.com Content-Language: en-US X-Greylist: Sender IP whitelisted, Sender e-mail whitelisted, not delayed by milter-greylist-4.4.3 (isis.lip6.fr [132.227.60.2]); Fri, 28 Aug 2020 21:43:13 +0200 (CEST) X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.4.3 (isis.lip6.fr [132.227.60.2]); Fri, 28 Aug 2020 00:03:23 +0200 (CEST) X-Scanned-By: MIMEDefang 2.78 on 132.227.60.2 X-Scanned-By: MIMEDefang 2.78 on 132.227.60.2 X-Mailman-Approved-At: Fri, 28 Aug 2020 21:43:10 +0200 Cc: "Gustavo A. R. Silva" , Kees Cook , Greg Kroah-Hartman , "linux-usb@vger.kernel.org" , Rasmus Villemoes , "linux-kernel@vger.kernel.org" , cocci , "accessrunner-general@lists.sourceforge.net" , Alex Dewar Subject: Re: [Cocci] [PATCH] usb: atm: don't use snprintf() for sysfs attrs X-BeenThere: cocci@systeme.lip6.fr X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: cocci-bounces@systeme.lip6.fr Errors-To: cocci-bounces@systeme.lip6.fr From: Joe Perches > Sent: 27 August 2020 21:30 ... > Perhaps what's necessary is to find any > appropriate .show function and change > any use of strcpy/sprintf within those > function to some other name. > > For instance: > > drivers/isdn/mISDN/core.c-static ssize_t name_show(struct device *dev, > drivers/isdn/mISDN/core.c- struct device_attribute *attr, char *buf) > drivers/isdn/mISDN/core.c-{ > drivers/isdn/mISDN/core.c: strcpy(buf, dev_name(dev)); > drivers/isdn/mISDN/core.c- return strlen(buf); > drivers/isdn/mISDN/core.c-} > drivers/isdn/mISDN/core.c-static DEVICE_ATTR_RO(name); That form ends up calculating the string length twice. Better would be: len = strlen(msg); memcpy(buf, msg, len); return len; David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales) _______________________________________________ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci