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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 541CCC0015E for ; Sat, 29 Jul 2023 12:01:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231355AbjG2MBI (ORCPT ); Sat, 29 Jul 2023 08:01:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231334AbjG2MBF (ORCPT ); Sat, 29 Jul 2023 08:01:05 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EF183C21 for ; Sat, 29 Jul 2023 05:00:58 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 9798F1F8A3; Sat, 29 Jul 2023 12:00:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1690632056; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=egMCYOG2uWRf43Q/bpZk0mUrDdU/hmHB0oSczsRgcao=; b=fOj76iqAakewDDQVg3ERFYSUceIt7FXI6JlQ6lqVO8CyUdWR40ud7wy+cFCKChbnaVTTWe z7MW6lpyDYO9CKnXZIu84EKiuJBQaQhrJEMq+wgVxj8qI0av88N04uEPa/8X62OhCYYUWP MemmXjpHbJMWduN8ubdjPZQpVMoJbMw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1690632056; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=egMCYOG2uWRf43Q/bpZk0mUrDdU/hmHB0oSczsRgcao=; b=X11RbWgLVHaVFMDD4fs+yMbTOlkTBvvV3L7WBcl8wn9fAfvlWx62BvCqodWUbixJ6Ye9SG 8+NF8hp2N8kibeDA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 6F00013596; Sat, 29 Jul 2023 12:00:56 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id +cUlGnj/xGT+ewAAMHmgww (envelope-from ); Sat, 29 Jul 2023 12:00:56 +0000 Date: Sat, 29 Jul 2023 14:00:55 +0200 Message-ID: <87leezc4g8.wl-tiwai@suse.de> From: Takashi Iwai To: Justin Stitt Cc: Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] ALSA: bcd2000: refactor deprecated strncpy In-Reply-To: <20230727-sound-usb-bcd2000-v1-1-0dc73684b2f0@google.com> References: <20230727-sound-usb-bcd2000-v1-1-0dc73684b2f0@google.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 28 Jul 2023 00:09:29 +0200, Justin Stitt wrote: > > `strncpy` is deprecated for use on NUL-terminated destination strings [1]. > > A suitable replacement is `strscpy` [2] due to the fact that it > guarantees NUL-termination on its destination buffer argument which is > _not_ always the case for `strncpy`! > > It should be noted that, in this case, the destination buffer has a > length strictly greater than the source string. Moreover, the source > string is NUL-terminated (and so is the destination) which means there > was no real bug happening here. Nonetheless, this patch would get us one > step closer to eliminating the `strncpy` API in the kernel, as its use > is too ambiguous. We need to favor less ambiguous replacements such as: > strscpy, strscpy_pad, strtomem and strtomem_pad (amongst others). > > Technically, my patch yields subtly different behavior. The original > implementation with `strncpy` would fill the entire destination buffer > with null bytes [3] while `strscpy` will leave the junk, uninitialized > bytes trailing after the _mandatory_ NUL-termination. So, if somehow > `card->driver` or `card->shortname` require this NUL-padding behavior > then `strscpy_pad` should be used. My interpretation, though, is that > the aforementioned fields are just fine as NUL-terminated strings. > Please correct my assumptions if needed and I'll send in a v2. > > [1]: www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings > [2]: manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html > [3]: https://linux.die.net/man/3/strncpy > > Link: https://github.com/KSPP/linux/issues/90 > Link: https://lore.kernel.org/r/20230727-sound-xen-v1-1-89dd161351f1@google.com (related ALSA patch) > Signed-off-by: Justin Stitt Applied now. Thanks. Takashi