Skip to content

Commit bb487d2

Browse files
Qian CaiSaeed Mahameed
authored andcommitted
net/mlx5: fix a -Wstringop-truncation warning
In file included from ./arch/powerpc/include/asm/paca.h:15, from ./arch/powerpc/include/asm/current.h:13, from ./include/linux/thread_info.h:21, from ./include/asm-generic/preempt.h:5, from ./arch/powerpc/include/generated/asm/preempt.h:1, from ./include/linux/preempt.h:78, from ./include/linux/spinlock.h:51, from ./include/linux/wait.h:9, from ./include/linux/completion.h:12, from ./include/linux/mlx5/driver.h:37, from drivers/net/ethernet/mellanox/mlx5/core/lib/eq.h:6, from drivers/net/ethernet/mellanox/mlx5/core/diag/fw_tracer.c:33: In function 'strncpy', inlined from 'mlx5_fw_tracer_save_trace' at drivers/net/ethernet/mellanox/mlx5/core/diag/fw_tracer.c:549:2, inlined from 'mlx5_tracer_print_trace' at drivers/net/ethernet/mellanox/mlx5/core/diag/fw_tracer.c:574:2: ./include/linux/string.h:305:9: warning: '__builtin_strncpy' output may be truncated copying 256 bytes from a string of length 511 [-Wstringop-truncation] return __builtin_strncpy(p, q, size); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Fix it by using the new strscpy_pad() since the commit 458a3bf ("lib/string: Add strscpy_pad() function") which will always NUL-terminate the string, and avoid possibly leak data through the ring buffer where non-admin account might enable these events through perf. Fixes: fd1483f ("net/mlx5: Add support for FW reporter dump") Signed-off-by: Qian Cai <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent e6806e9 commit bb487d2

File tree

1 file changed

+1
-1
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core/diag

1 file changed

+1
-1
lines changed

drivers/net/ethernet/mellanox/mlx5/core/diag/fw_tracer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ static void mlx5_fw_tracer_save_trace(struct mlx5_fw_tracer *tracer,
546546
trace_data->timestamp = timestamp;
547547
trace_data->lost = lost;
548548
trace_data->event_id = event_id;
549-
strncpy(trace_data->msg, msg, TRACE_STR_MSG);
549+
strscpy_pad(trace_data->msg, msg, TRACE_STR_MSG);
550550

551551
tracer->st_arr.saved_traces_index =
552552
(tracer->st_arr.saved_traces_index + 1) & (SAVED_TRACES_NUM - 1);

0 commit comments

Comments
 (0)