Skip to content

Commit

Permalink
tracing: Change trace event sample to use strlcpy instead of strncpy
Browse files Browse the repository at this point in the history
Strings should be copied with strlcpy instead of strncpy when they will
later be printed via %s. This guarantees that they terminate with a
NUL '\0' character and do not run pass the end of the allocated string.

This is only for sample code, but it should stil represent a good
role model.

Link: http://lkml.kernel.org/p/[email protected]

Signed-off-by: Zhao Hongjiang <[email protected]>
Signed-off-by: Steven Rostedt <[email protected]>
  • Loading branch information
Zhao Hongjiang authored and rostedt committed Jul 1, 2014
1 parent 9674b2f commit d8fae2f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion samples/trace_events/trace-events-sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ TRACE_EVENT(foo_bar,
),

TP_fast_assign(
strncpy(__entry->foo, foo, 10);
strlcpy(__entry->foo, foo, 10);
__entry->bar = bar;
),

Expand Down

0 comments on commit d8fae2f

Please sign in to comment.