Re: [PATCH] firmware: tegra: fix strncpy()/strncat() confusion
From: Arnd Bergmann
Date: Mon Oct 26 2020 - 12:50:34 EST
On Mon, Oct 26, 2020 at 5:40 PM Arnd Bergmann <arnd@xxxxxxxxxx> wrote:
> On Mon, Oct 26, 2020 at 5:35 PM Arvind Sankar <nivedita@xxxxxxxxxxxx> wrote:
> > > diff --git a/drivers/firmware/tegra/bpmp-debugfs.c b/drivers/firmware/tegra/bpmp-debugfs.c
> > > index c1bbba9ee93a..9ec20ddc9a6b 100644
> > > --- a/drivers/firmware/tegra/bpmp-debugfs.c
> > > +++ b/drivers/firmware/tegra/bpmp-debugfs.c
> > > @@ -412,16 +412,12 @@ static int bpmp_populate_debugfs_inband(struct tegra_bpmp *bpmp,
> > > goto out;
> > > }
> > >
> > > - len = strlen(ppath) + strlen(name) + 1;
> > > + len = snprintf("%s%s/", pathlen, ppath, name);
> >
> > Didn't you get any warnings with this? It should be
> > len = snprintf(pathbuf, pathlen, "%s%s/", ppath, name);
> > right?
> >
>
> Eek, I did get a warning about a different issue in that one-line change and
> fixed it up in the wrong way without testing again. Sorry about that.
Actually it turns out that gcc did not warn about my broken version.
The argument types are (roughly) correct and as the third argument
is not a constant string it could not verify the format string. Maybe it
should have complained about the constant string used as an output,
but it doesn't seem to care about that.
Arnd