History

tracing: Fix strncpy warning in trace_events_synth.c

0-day reported the strncpy error below: ../kernel/trace/trace_events_synth.c: In function 'last_cmd_set': ../kernel/trace/trace_events_synth.c:65:9: warning: 'strncpy' specified bound depends on the length o\ f the source argument [-Wstringop-truncation] 65 | strncpy(last_cmd, str, strlen(str) + 1); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../kernel/trace/trace_events_synth.c:65:32: note: length computed here 65 | strncpy(last_cmd, str, strlen(str) + 1); | ^~~~~~~~~~~ There's no reason to use strncpy here, in fact there's no reason to do anything but a simple kstrdup() (note we don't even need to check for failure since last_cmod is expected to be either the last cmd string or NULL, and the containing function is a void return). Link: https://lkml.kernel.org/r/77deca8cbfd226981b3f1eab203967381e9b5bd9.camel@kernel.org Fixes: 27c888da9867 ("tracing: Remove size restriction on synthetic event cmd error logging")

Tom Zanussi committed 4 years ago

Commit 9f438d41 parent 7e348b31 file · +1 −4Browse files

Showing the changes to kernel (1 of 1 file). Show all

Unified · Split

kernel/trace/trace_events_synth.c+1−4
@@ -58,11 +58,8 @@ static void last_cmd_set(const char *str) · 57 unmodified lines
5858 return;
5959
6060 kfree(last_cmd);
61− last_cmd = kzalloc(strlen(str) + 1, GFP_KERNEL);
62− if (!last_cmd)
63− return;
6461
65− strncpy(last_cmd, str, strlen(str) + 1);
62+ last_cmd = kstrdup(str, GFP_KERNEL);
6663 }
6764
6865 static void synth_err(u8 err_type, u16 err_pos)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t