Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp3902483rwl; Tue, 27 Dec 2022 17:49:19 -0800 (PST) X-Google-Smtp-Source: AMrXdXtUJHUAq04EfCstRpfOW6rqV2uFBJHW4ptNDMOyAt9F1FgwekhKRzAWWIK2sLs5NxHJYszb X-Received: by 2002:a05:6a20:7f5e:b0:ac:3853:cacd with SMTP id e30-20020a056a207f5e00b000ac3853cacdmr22254340pzk.38.1672192159228; Tue, 27 Dec 2022 17:49:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672192159; cv=none; d=google.com; s=arc-20160816; b=Q5fADNepJv3rrHTEhuQe0gGKCGwtiIXqc8xVZcU6yA4e3TKgFZeg7qkXaajMqrafx2 2+TVW5DJL8c4e51+TvnU85g5U2v2IQBmvy5gLDVq4NC6Z5Dmuz60XN6zOCucgHa+jGqF yVxJdrMfTESqP53Z0Z3T1Zsrgn5ApVAcC4DUbTXZGnfYN/Ua9eoEkGoN7qacO1HuOFZ/ 1vBRyJeJLD4L8GIc1RgAZg90Krw5trzRRBlHhSGcr+9F58sHo4nwCuOcNwgmkvjjmNBu yX9OgGgZxSAwNb/i0x/85VzvltyMA1Bm0xuGWbQu705/iXmszNTxRnuuV9tYe6LPnXrz QMhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:mime-version:message-id:date; bh=9oABMmIFPYELItHsgEdArCZl6RwjSTrpyVHCYoEnjZ0=; b=kkfzc/yTzvzU2zGIqmOd64AjhB5bGUZCzHmJ9snZviU3qWrqQsAon/IxBOLJ6SQgXJ f0q7Iq8YUn6IcXKLuvClvl9DVPOWmxKd2jWfY7NbnhkIl8e8wfY9NYQNThuxoIIdOiOp bQ+PT8rTx8cd2CBlvyuQ7iEA3pTvpnrAt2WmlQwSjti3YEBRUTLwtBF7bzvvE7gTjBTn 0JCzevqBJOgtdtaG8EdFwjogEzlmqe5V74yy1hFotmhTkeZAgwsWTz5upNKj7dEVsTvM akC1l4ZO5qJpC9ZEKSxL54u2IbZ3pC8aCr3yc2BrSjHgEbN934StYxsUHNLNOhFV7w7x 5Cuw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j186-20020a638bc3000000b00478a31bc456si15837598pge.29.2022.12.27.17.49.10; Tue, 27 Dec 2022 17:49:19 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231716AbiL1BhD (ORCPT + 65 others); Tue, 27 Dec 2022 20:37:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229475AbiL1BhB (ORCPT ); Tue, 27 Dec 2022 20:37:01 -0500 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E93E1C777; Tue, 27 Dec 2022 17:36:59 -0800 (PST) Received: from mse-fl1.zte.com.cn (unknown [10.5.228.132]) (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 4NhYzG2lLHz6FK2R; Wed, 28 Dec 2022 09:36:58 +0800 (CST) Received: from szxlzmapp06.zte.com.cn ([10.5.230.252]) by mse-fl1.zte.com.cn with SMTP id 2BS1argD046602; Wed, 28 Dec 2022 09:36:53 +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:36:54 +0800 (CST) Date: Wed, 28 Dec 2022 09:36:54 +0800 (CST) X-Zmail-TransId: 2b0363ab9db6ffffffff8f6431d8 X-Mailer: Zmail v1.0 Message-ID: <202212280936545669762@zte.com.cn> Mime-Version: 1.0 From: To: Cc: , , , , , Subject: =?UTF-8?B?W1BBVENIIGxpbnV4LW5leHRdIGVjcnlwdGZzOiBjcnlwdG86IHVzZSBzdHJzY3B5KCkgdG8gaW5zdGVhZCBvZiBzdHJuY3B5KCk=?= Content-Type: text/plain; charset="UTF-8" X-MAIL: mse-fl1.zte.com.cn 2BS1argD046602 X-Fangmail-Gw-Spam-Type: 0 X-FangMail-Miltered: at cgslv5.04-192.168.250.138.novalocal with ID 63AB9DBA.000 by FangMail milter! X-FangMail-Envelope: 1672191418/4NhYzG2lLHz6FK2R/63AB9DBA.000/10.5.228.132/[10.5.228.132]/mse-fl1.zte.com.cn/ X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 63AB9DBA.000/4NhYzG2lLHz6FK2R X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,UNPARSEABLE_RELAY 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 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/crypto.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index 03263ebcccc6..c618a6878584 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c @@ -1630,9 +1630,8 @@ ecryptfs_add_new_key_tfm(struct ecryptfs_key_tfm **key_tfm, char *cipher_name, goto out; } mutex_init(&tmp_tfm->key_tfm_mutex); - strncpy(tmp_tfm->cipher_name, cipher_name, - ECRYPTFS_MAX_CIPHER_NAME_SIZE); - tmp_tfm->cipher_name[ECRYPTFS_MAX_CIPHER_NAME_SIZE] = '\0'; + strscpy(tmp_tfm->cipher_name, cipher_name, + ECRYPTFS_MAX_CIPHER_NAME_SIZE + 1); tmp_tfm->key_size = key_size; rc = ecryptfs_process_key_cipher(&tmp_tfm->key_tfm, tmp_tfm->cipher_name, -- 2.15.2