[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4BzYGjNaqL4h8=4Jw7O_xxMfy=TbUg94VO6RZT5wOtV+_wQ@mail.gmail.com>
Date: Wed, 13 Jul 2022 11:40:01 -0700
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Jiri Olsa <olsajiri@...il.com>,
Alan Maguire <alan.maguire@...cle.com>
Cc: Fedor Tokarev <ftokarev@...il.com>,
Martin KaFai Lau <martin.lau@...ux.dev>,
bpf <bpf@...r.kernel.org>,
open list <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] bpf: btf: Fix vsnprintf return value check
On Mon, Jul 11, 2022 at 2:45 PM Jiri Olsa <olsajiri@...il.com> wrote:
>
> On Mon, Jul 11, 2022 at 11:13:17PM +0200, Fedor Tokarev wrote:
> > vsnprintf returns the number of characters which would have been written if
> > enough space had been available, excluding the terminating null byte. Thus,
> > the return value of 'len_left' means that the last character has been
> > dropped.
>
> should we have test for this in progs/test_snprintf.c ?
It might be too annoying to set up such test, and given the fix is
pretty trivial IMO it's ok without extra test. But cc Alan for ack.
Alan, please take a look as well.
>
> jirka
>
> >
> > Signed-off-by: Fedor Tokarev <ftokarev@...il.com>
> > ---
> > kernel/bpf/btf.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> > index eb12d4f705cc..a9c1c98017d4 100644
> > --- a/kernel/bpf/btf.c
> > +++ b/kernel/bpf/btf.c
> > @@ -6519,7 +6519,7 @@ static void btf_snprintf_show(struct btf_show *show, const char *fmt,
> > if (len < 0) {
> > ssnprintf->len_left = 0;
> > ssnprintf->len = len;
> > - } else if (len > ssnprintf->len_left) {
> > + } else if (len >= ssnprintf->len_left) {
> > /* no space, drive on to get length we would have written */
> > ssnprintf->len_left = 0;
> > ssnprintf->len += len;
> > --
> > 2.25.1
> >
Powered by blists - more mailing lists