lkml.org 
[lkml]   [2018]   [May]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH] blk-wbt: tracing: prefer strlcpy to strncpy
On Mon, May 28, 2018 at 11:31 PM, Nick Desaulniers
<nick.desaulniers@gmail.com> wrote:
> Fixes a stringop-truncation warning from gcc-8.
>
> Signed-off-by: Nick Desaulniers <nick.desaulniers@gmail.com>
> ---
> include/trace/events/wbt.h | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/include/trace/events/wbt.h b/include/trace/events/wbt.h
> index b048694..305252d 100644
> --- a/include/trace/events/wbt.h
> +++ b/include/trace/events/wbt.h
> @@ -33,7 +33,7 @@ TRACE_EVENT(wbt_stat,
> ),
>
> TP_fast_assign(
> - strncpy(__entry->name, dev_name(bdi->dev), 32);
> + strlcpy(__entry->name, dev_name(bdi->dev), 32);
> __entry->rmean = stat[0].mean;
> __entry->rmin = stat[0].min;
> __entry->rmax = stat[0].max;
> @@ -67,7 +67,7 @@ TRACE_EVENT(wbt_lat,
> ),
>
> TP_fast_assign(
> - strncpy(__entry->name, dev_name(bdi->dev), 32);
> + strlcpy(__entry->name, dev_name(bdi->dev), 32);
> __entry->lat = div_u64(lat, 1000);
> ),
>
> @@ -103,7 +103,7 @@ TRACE_EVENT(wbt_step,
> ),
>
> TP_fast_assign(
> - strncpy(__entry->name, dev_name(bdi->dev), 32);
> + strlcpy(__entry->name, dev_name(bdi->dev), 32);
> __entry->msg = msg;
> __entry->step = step;
> __entry->window = div_u64(window, 1000);
> @@ -138,7 +138,7 @@ TRACE_EVENT(wbt_timer,
> ),
>
> TP_fast_assign(
> - strncpy(__entry->name, dev_name(bdi->dev), 32);
> + strlcpy(__entry->name, dev_name(bdi->dev), 32);
> __entry->status = status;
> __entry->step = step;
> __entry->inflight = inflight;
> --
> 2.7.4
>

Eric points out this doesn't initialize the rest of dest if src is
less than size.

\
 
 \ /
  Last update: 2018-05-30 03:58    [W:0.048 / U:3.116 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site