linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH linux-next] blktrace: use strscpy() to instead of strncpy()
@ 2023-01-05 12:16 yang.yang29
  0 siblings, 0 replies; only message in thread
From: yang.yang29 @ 2023-01-05 12:16 UTC (permalink / raw)
  To: axboe
  Cc: rostedt, mhiramat, linux-block, linux-kernel, linux-trace-kernel,
	xu.panda, yang.yang29

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.cn>
---
 kernel/trace/blktrace.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 918a7d12df8f..ff0cc68d7667 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -524,8 +524,7 @@ static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
 	if (!buts->buf_size || !buts->buf_nr)
 		return -EINVAL;

-	strncpy(buts->name, name, BLKTRACE_BDEV_SIZE);
-	buts->name[BLKTRACE_BDEV_SIZE - 1] = '\0';
+	strscpy(buts->name, name, BLKTRACE_BDEV_SIZE);

 	/*
 	 * some device names have larger paths - convert the slashes
-- 
2.15.2

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-01-05 12:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-05 12:16 [PATCH linux-next] blktrace: use strscpy() to instead of strncpy() yang.yang29

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).