From nobody Tue Sep 16 21:44:28 2025 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 7D9F8C10F1B for ; Wed, 28 Dec 2022 01:38:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230240AbiL1Bim (ORCPT ); Tue, 27 Dec 2022 20:38:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230125AbiL1Bie (ORCPT ); Tue, 27 Dec 2022 20:38:34 -0500 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DB111F4; Tue, 27 Dec 2022 17:38:34 -0800 (PST) Received: from mse-fl2.zte.com.cn (unknown [10.5.228.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxhk.zte.com.cn (FangMail) with ESMTPS id 4NhZ14523Lz5PkHg; Wed, 28 Dec 2022 09:38:32 +0800 (CST) Received: from szxlzmapp04.zte.com.cn ([10.5.231.166]) by mse-fl2.zte.com.cn with SMTP id 2BS1cRF9022734; Wed, 28 Dec 2022 09:38:27 +0800 (+08) (envelope-from yang.yang29@zte.com.cn) Received: from mapi (szxlzmapp01[null]) by mapi (Zmail) with MAPI id mid14; Wed, 28 Dec 2022 09:38:27 +0800 (CST) Date: Wed, 28 Dec 2022 09:38:27 +0800 (CST) X-Zmail-TransId: 2b0363ab9e13ffffffff85849134 X-Mailer: Zmail v1.0 Message-ID: <202212280938279799834@zte.com.cn> Mime-Version: 1.0 From: To: Cc: , , , , , Subject: =?UTF-8?B?W1BBVENIIGxpbnV4LW5leHRdIGVjcnlwdGZzOiBtYWluOiB1c2Ugc3Ryc2NweSgpIHRvIGluc3RlYWQgb2Ygc3RybmNweSgp?= X-MAIL: mse-fl2.zte.com.cn 2BS1cRF9022734 X-Fangmail-Gw-Spam-Type: 0 X-FangMail-Miltered: at cgslv5.04-192.168.250.138.novalocal with ID 63AB9E18.000 by FangMail milter! X-FangMail-Envelope: 1672191512/4NhZ14523Lz5PkHg/63AB9E18.000/10.5.228.133/[10.5.228.133]/mse-fl2.zte.com.cn/ X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 63AB9E18.000/4NhZ14523Lz5PkHg Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Xu Panda The implementation of strscpy() is more robust and safer. That's now the recommended way to copy NUL-terminated strings. Signed-off-by: Xu Panda Signed-off-by: Yang Yang --- fs/ecryptfs/main.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c index 2dc927ba067f..007bed5ddf6e 100644 --- a/fs/ecryptfs/main.c +++ b/fs/ecryptfs/main.c @@ -296,9 +296,8 @@ static int ecryptfs_parse_options(struct ecryptfs_sb_in= fo *sbi, char *options, cipher_name_dst =3D mount_crypt_stat-> global_default_cipher_name; - strncpy(cipher_name_dst, cipher_name_src, - ECRYPTFS_MAX_CIPHER_NAME_SIZE); - cipher_name_dst[ECRYPTFS_MAX_CIPHER_NAME_SIZE] =3D '\0'; + strscpy(cipher_name_dst, cipher_name_src, + ECRYPTFS_MAX_CIPHER_NAME_SIZE + 1); cipher_name_set =3D 1; break; case ecryptfs_opt_ecryptfs_key_bytes: @@ -328,9 +327,7 @@ static int ecryptfs_parse_options(struct ecryptfs_sb_in= fo *sbi, char *options, fnek_src =3D args[0].from; fnek_dst =3D mount_crypt_stat->global_default_fnek_sig; - strncpy(fnek_dst, fnek_src, ECRYPTFS_SIG_SIZE_HEX); - mount_crypt_stat->global_default_fnek_sig[ - ECRYPTFS_SIG_SIZE_HEX] =3D '\0'; + strscpy(fnek_dst, fnek_src, ECRYPTFS_SIG_SIZE_HEX + 1); rc =3D ecryptfs_add_global_auth_tok( mount_crypt_stat, mount_crypt_stat->global_default_fnek_sig, @@ -350,10 +347,8 @@ static int ecryptfs_parse_options(struct ecryptfs_sb_i= nfo *sbi, char *options, fn_cipher_name_src =3D args[0].from; fn_cipher_name_dst =3D mount_crypt_stat->global_default_fn_cipher_name; - strncpy(fn_cipher_name_dst, fn_cipher_name_src, - ECRYPTFS_MAX_CIPHER_NAME_SIZE); - mount_crypt_stat->global_default_fn_cipher_name[ - ECRYPTFS_MAX_CIPHER_NAME_SIZE] =3D '\0'; + strscpy(fn_cipher_name_dst, fn_cipher_name_src, + ECRYPTFS_MAX_CIPHER_NAME_SIZE + 1); fn_cipher_name_set =3D 1; break; case ecryptfs_opt_fn_cipher_key_bytes: --=20 2.15.2