public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: <yang.yang29@zte.com.cn>
To: <arnd@arndb.de>
Cc: <u.kleine-koenig@pengutronix.de>,
	<wsa+renesas@sang-engineering.com>,
	<benjamin.mugnier@foss.st.com>,
	<andriy.shevchenko@linux.intel.com>, <error27@gmail.com>,
	<justinstitt@google.com>, <linux-kernel@vger.kernel.org>,
	<xu.panda@zte.com.cn>, <yang.yang29@zte.com.cn>
Subject: [PATCH linux-next] misc: eeprom/idt_89hpesx: use strscpy() to instead of
 strncpy() 
Date: Wed, 7 Dec 2022 09:14:24 +0800 (CST)	[thread overview]
Message-ID: <202212070914242210002@zte.com.cn> (raw)

From: Xu Panda <xu.panda@zte.com.cn>

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 <xu.panda@zte.com.cn>
Signed-off-by: Yang Yang <yang.yang29@zte.com>
---
 drivers/misc/eeprom/idt_89hpesx.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/misc/eeprom/idt_89hpesx.c b/drivers/misc/eeprom/idt_89hpesx.c
index 4e07ee9cb500..57b985fe59f4 100644
--- a/drivers/misc/eeprom/idt_89hpesx.c
+++ b/drivers/misc/eeprom/idt_89hpesx.c
@@ -941,8 +941,7 @@ static ssize_t idt_dbgfs_csr_write(struct file *filep, const char __user *ubuf,
 			goto free_buf;
 		}
 		/* Copy the register address to the substring buffer */
-		strncpy(csraddr_str, buf, csraddr_len);
-		csraddr_str[csraddr_len] = '\0';
+		strscpy(csraddr_str, buf, csraddr_len + 1);
 		/* Register value must follow the colon */
 		csrval_str = colon_ch + 1;
 	} else /* if (str_colon == NULL) */ {
-- 
2.15.2

                 reply	other threads:[~2022-12-07  1:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202212070914242210002@zte.com.cn \
    --to=yang.yang29@zte.com.cn \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=arnd@arndb.de \
    --cc=benjamin.mugnier@foss.st.com \
    --cc=error27@gmail.com \
    --cc=justinstitt@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=u.kleine-koenig@pengutronix.de \
    --cc=wsa+renesas@sang-engineering.com \
    --cc=xu.panda@zte.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox