2018-05-29 06:04:29

by Nick Desaulniers

[permalink] [raw]
Subject: [PATCH] tracing: prefer strlcpy to strncpy

Fixes a stringop-truncation warning from gcc-8.

Signed-off-by: Nick Desaulniers <[email protected]>
---
kernel/trace/trace_events_hist.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index b9061ed..b53a6c0 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -393,7 +393,7 @@ static void hist_err_event(char *str, char *system, char *event, char *var)
else if (system)
snprintf(err, MAX_FILTER_STR_VAL, "%s.%s", system, event);
else
- strncpy(err, var, MAX_FILTER_STR_VAL);
+ strlcpy(err, var, MAX_FILTER_STR_VAL);

hist_err(str, err);
}
--
2.7.4



2018-05-30 01:56:05

by Nick Desaulniers

[permalink] [raw]
Subject: Re: [PATCH] tracing: prefer strlcpy to strncpy

On Mon, May 28, 2018 at 11:03 PM, Nick Desaulniers
<[email protected]> wrote:
> Fixes a stringop-truncation warning from gcc-8.
>
> Signed-off-by: Nick Desaulniers <[email protected]>
> ---
> kernel/trace/trace_events_hist.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
> index b9061ed..b53a6c0 100644
> --- a/kernel/trace/trace_events_hist.c
> +++ b/kernel/trace/trace_events_hist.c
> @@ -393,7 +393,7 @@ static void hist_err_event(char *str, char *system, char *event, char *var)
> else if (system)
> snprintf(err, MAX_FILTER_STR_VAL, "%s.%s", system, event);
> else
> - strncpy(err, var, MAX_FILTER_STR_VAL);
> + strlcpy(err, var, MAX_FILTER_STR_VAL);
>
> hist_err(str, err);
> }
> --
> 2.7.4
>

Eric points out this wont initialize the rest of err with zeros.

2018-06-04 18:07:34

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH] tracing: prefer strlcpy to strncpy

On Mon, 28 May 2018 23:03:38 -0700
Nick Desaulniers <[email protected]> wrote:

> Fixes a stringop-truncation warning from gcc-8.
>
> Signed-off-by: Nick Desaulniers <[email protected]>

Acked-by: Steven Rostedt (VMware) <[email protected]>

-- Steve

> ---
> kernel/trace/trace_events_hist.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
> index b9061ed..b53a6c0 100644
> --- a/kernel/trace/trace_events_hist.c
> +++ b/kernel/trace/trace_events_hist.c
> @@ -393,7 +393,7 @@ static void hist_err_event(char *str, char *system, char *event, char *var)
> else if (system)
> snprintf(err, MAX_FILTER_STR_VAL, "%s.%s", system, event);
> else
> - strncpy(err, var, MAX_FILTER_STR_VAL);
> + strlcpy(err, var, MAX_FILTER_STR_VAL);
>
> hist_err(str, err);
> }


2018-06-04 18:11:46

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH] tracing: prefer strlcpy to strncpy

On Tue, 29 May 2018 18:55:23 -0700
Nick Desaulniers <[email protected]> wrote:

> On Mon, May 28, 2018 at 11:03 PM, Nick Desaulniers
> <[email protected]> wrote:
> > Fixes a stringop-truncation warning from gcc-8.
> >
> > Signed-off-by: Nick Desaulniers <[email protected]>
> > ---
> > kernel/trace/trace_events_hist.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
> > index b9061ed..b53a6c0 100644
> > --- a/kernel/trace/trace_events_hist.c
> > +++ b/kernel/trace/trace_events_hist.c
> > @@ -393,7 +393,7 @@ static void hist_err_event(char *str, char *system, char *event, char *var)
> > else if (system)
> > snprintf(err, MAX_FILTER_STR_VAL, "%s.%s", system, event);
> > else
> > - strncpy(err, var, MAX_FILTER_STR_VAL);
> > + strlcpy(err, var, MAX_FILTER_STR_VAL);
> >
> > hist_err(str, err);
> > }
> > --
> > 2.7.4
> >
>
> Eric points out this wont initialize the rest of err with zeros.

And why do we care?

-- Steve