Skip to content

Commit 051e750

Browse files
arndbakpm00
authored andcommitted
blktrace: convert strncpy() to strscpy_pad()
gcc-9 warns about a possibly non-terminated string copy: kernel/trace/blktrace.c: In function 'do_blk_trace_setup': kernel/trace/blktrace.c:527:2: error: 'strncpy' specified bound 32 equals destination size [-Werror=stringop-truncation] Newer versions are fine here because they see the following explicit nul-termination. Using strscpy_pad() avoids the warning and simplifies the code a little. The padding helps give a clean buffer to userspace. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Arnd Bergmann <[email protected]> Acked-by: Justin Stitt <[email protected]> Cc: Alexey Starikovskiy <[email protected]> Cc: Bob Moore <[email protected]> Cc: Jens Axboe <[email protected]> Cc: Len Brown <[email protected]> Cc: Lin Ming <[email protected]> Cc: Masahiro Yamada <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Nathan Chancellor <[email protected]> Cc: Nicolas Schier <[email protected]> Cc: Rafael J. Wysocki <[email protected]> Cc: "Richard Russon (FlatCap)" <[email protected]> Cc: Steven Rostedt <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 597bc74 commit 051e750

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

kernel/trace/blktrace.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,7 @@ static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
524524
if (!buts->buf_size || !buts->buf_nr)
525525
return -EINVAL;
526526

527-
strncpy(buts->name, name, BLKTRACE_BDEV_SIZE);
528-
buts->name[BLKTRACE_BDEV_SIZE - 1] = '\0';
527+
strscpy_pad(buts->name, name, BLKTRACE_BDEV_SIZE);
529528

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

0 commit comments

Comments
 (0)