lkml.org 
[lkml]   [2014]   [Jul]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    From
    Subject[for-next][PATCH 06/21] tracing: Change trace event sample to use strlcpy instead of strncpy
    From: Zhao Hongjiang <zhaohongjiang@huawei.com>

    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/51C2E204.1080501@huawei.com

    Signed-off-by: Zhao Hongjiang <zhaohongjiang@huawei.com>
    Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
    ---
    samples/trace_events/trace-events-sample.h | 2 +-
    1 file changed, 1 insertion(+), 1 deletion(-)

    diff --git a/samples/trace_events/trace-events-sample.h b/samples/trace_events/trace-events-sample.h
    index 4b0113f73ee9..476429281389 100644
    --- a/samples/trace_events/trace-events-sample.h
    +++ b/samples/trace_events/trace-events-sample.h
    @@ -87,7 +87,7 @@ TRACE_EVENT(foo_bar,
    ),

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

    --
    2.0.0



    \
     
     \ /
      Last update: 2014-07-03 19:01    [W:4.184 / U:0.772 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site