Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp2427685rwb; Sat, 29 Jul 2023 06:44:26 -0700 (PDT) X-Google-Smtp-Source: APBJJlFX5dDTHViiY8Gq1eqiYV4jk3xDuPADELc2XhhtX+6aya9cN6ab6lfnJPTXKnsY6GzxBXuZ X-Received: by 2002:a17:902:b605:b0:1b8:b382:f6c6 with SMTP id b5-20020a170902b60500b001b8b382f6c6mr4528934pls.9.1690638265878; Sat, 29 Jul 2023 06:44:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690638265; cv=none; d=google.com; s=arc-20160816; b=sWcFlwhWZZO62u3spScTyIwzLL9m3kuCFP/ZGk5hnVORnpw6+JKKHiy9dm8XXftpYJ tmbEXRd1acupFs+R6ANx8kPMLQ0w35VqLacMTkgTBvmaNUeuXACI7sc7B9lW2jYPTnor aQ8Q6jJOpsPN4I+Z+9zC+Gcv2+caaW9/+o8aFWlFiY1gAebuyRTxBM1i+9b34TTPZWz3 9E6Ts93GD6set/lUnkwT+qlZs0MGp8i5KeYDJMuHREWN8Up2zTjr6/zJohaM9kb5PXMB sTIigAt3Sg9yU/K53qJIFRQ2CpQ56Tw49I2FT/YsWqZSi/vTsP4QcJFmWRGUxGsOnLhp hVmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature:dkim-signature; bh=egMCYOG2uWRf43Q/bpZk0mUrDdU/hmHB0oSczsRgcao=; fh=LwPoM4aaLCXkyzKiSICwfa7rHe1aFxYqwcdBLhZ1Twk=; b=a/ZRBSO4uL3h02/2y+Zne4JvdO+gTCgn4hLZn4QRkzDiNSR3ZK1PpPOs1QqJqsd77j EG5aahw6X9828J3EChpvd0Uk2YFrRGt8lFo61IErrpCt1y3CdJInYGchpA9gskPrPAfV Y0etZqzRLPuAC+DenBb3EDHfNqXp5h++D3lpM6QFIxvQhMOuVfhts7oVbPV/AmF37u+L dqtDs7+0T5FY8HyaskQJdB7zM70b/hbNWXRrvZkWIITayCgJlHdOGfOe5fujMXTCSb1a ztXZn2lZ4k5nE6siCZsH/4AKjdjuO/KF1UjOWgAa8sPq8rqjiZBL42a81MgiZbYrGqwD HFJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=fOj76iqA; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kr4-20020a170903080400b001bb94eaa311si4428034plb.567.2023.07.29.06.44.13; Sat, 29 Jul 2023 06:44:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=fOj76iqA; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230440AbjG2MBG (ORCPT + 99 others); Sat, 29 Jul 2023 08:01:06 -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 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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