Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp354928rdb; Thu, 30 Nov 2023 06:41:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IF9dBo0/9Tv6AwXnQNdEgWwRtO5y4ET08Zj9OCfgysaF1JqO7Grc2VVqroRfrH3w0FqPVlY X-Received: by 2002:a17:902:d489:b0:1cf:f7c3:1e32 with SMTP id c9-20020a170902d48900b001cff7c31e32mr10435418plg.27.1701355289333; Thu, 30 Nov 2023 06:41:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701355289; cv=none; d=google.com; s=arc-20160816; b=hnNQcCPi+/7cm4000UlmGfjTo3bseER1ps0WEHOupJ+5ElsRbQjZNPqaWonZ1OXR1T o02wXUBoJKyy6BQ0iOc5DY75B86ajjxB/6TevLM4thZpxngY2UfRc0mYfh13gJ42gInN oQYUqxDOqRj/fWmAGqlutIMVgVFi4sgZPOROuz0HAyADieucoR71VRasppGFZMLGk7tW OE07+E/FgJGMiW7tNLt2qXa9ZPKMu5dCoS7WSmRSEC6mK1YORWBTJNizC0SF7PIMGeSM VLplufMlbeqNZNaKfdT5qtpE8TUOkfAIh3bxMKN0vwviqqN8mxg3UBEyAzb/9fqRnReQ vmhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=H555X1m/V+e7KJiGQzoeQ3ppZkcv80bGX8Zh/H79auM=; fh=s5xHQp2NohXvJx5pR63lAuTpJSXapwBSp5zhwVzEkFc=; b=05u6jSnxSvmyt9cFyssXOy8wbd9rua7+y4VEimE1zIt67y28eTPpfllpkXCk4Oqj1d YdKAmLbfbdEymXZE3nMU3y+7B80IYIx5d+rvPv9VSS+uvweLprUrU4fSGtkobzRSWFT2 GCe/Qu5kylg1cISgWJB5zL8lu2+92cOM8cwqiuK5sTSky9/3BzrexweQ54gsFbLsqeM8 B3YPQ1M0WQxDltKHRGvLogb4DPdYnPERlmNlUXtabiKcV2SxKaHFPKLpJcFmPj7HBBZ0 6Euk7qU7y3ahQJIrFihdG0UIE7zZBNnxQIWMWVFD4X8XZZrATwmqcnobT1pOSDZZtlEs toRA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id a3-20020a170902ecc300b001cfe03b2bafsi1445124plh.491.2023.11.30.06.41.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 06:41:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 402CC8292A7C; Thu, 30 Nov 2023 06:41:20 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232142AbjK3OlE convert rfc822-to-8bit (ORCPT + 99 others); Thu, 30 Nov 2023 09:41:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235195AbjK3OlC (ORCPT ); Thu, 30 Nov 2023 09:41:02 -0500 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F5A0BD for ; Thu, 30 Nov 2023 06:41:07 -0800 (PST) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-48-t3ILSSs2OZqhiSRZq3Dljg-2; Thu, 30 Nov 2023 14:40:57 +0000 X-MC-Unique: t3ILSSs2OZqhiSRZq3Dljg-2 Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Thu, 30 Nov 2023 14:40:12 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Thu, 30 Nov 2023 14:40:12 +0000 From: David Laight To: 'Lee Jones' CC: "linux-kernel@vger.kernel.org" , "Linus Walleij" , Greg Kroah-Hartman , Yuan-Hsin Chen , Feng-Hsin Chiang , Po-Yu Chuang , "linux-usb@vger.kernel.org" Subject: RE: [PATCH 3/5] usb: fotg210-hcd: Replace snprintf() with the safer scnprintf() variant Thread-Topic: [PATCH 3/5] usb: fotg210-hcd: Replace snprintf() with the safer scnprintf() variant Thread-Index: AQHaI3u56JraFtMggUKBqY7WM/KeMLCS64WA Date: Thu, 30 Nov 2023 14:40:12 +0000 Message-ID: References: <20231130105459.3208986-1-lee@kernel.org> <20231130105459.3208986-4-lee@kernel.org> In-Reply-To: <20231130105459.3208986-4-lee@kernel.org> 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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 30 Nov 2023 06:41:20 -0800 (PST) From: Lee Jones > Sent: 30 November 2023 10:55 > > There is a general misunderstanding amongst engineers that {v}snprintf() > returns the length of the data *actually* encoded into the destination > array. However, as per the C99 standard {v}snprintf() really returns > the length of the data that *would have been* written if there were > enough space for it. This misunderstanding has led to buffer-overruns > in the past. It's generally considered safer to use the {v}scnprintf() > variants in their place (or even sprintf() in simple cases). So let's > do that. > > The uses in this file both seem to assume that data *has been* written! ... > - temp = snprintf(next, size, > - "\n\t%p%c%s len=%d %08x urb %p", > - td, mark, ({ char *tmp; ... > - if (size < temp) > - temp = size; That is actually a bug - even though it is trying to be correct. The trailing '\0' that snprintf() adds (unless you are using the M$ one) will end up in the buffer. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)