From: Jiri Olsa <olsajiri@gmail.com>
To: Fedor Tokarev <ftokarev@gmail.com>
Cc: Martin KaFai Lau <martin.lau@linux.dev>,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] bpf: btf: Fix vsnprintf return value check
Date: Mon, 11 Jul 2022 23:42:59 +0200 [thread overview]
Message-ID: <YsyZY/tFm3hi5srl@krava> (raw)
In-Reply-To: <20220711211317.GA1143610@laptop>
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 ?
jirka
>
> Signed-off-by: Fedor Tokarev <ftokarev@gmail.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
>
next prev parent reply other threads:[~2022-07-11 21:43 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-11 21:13 [PATCH] bpf: btf: Fix vsnprintf return value check Fedor Tokarev
2022-07-11 21:42 ` Jiri Olsa [this message]
2022-07-13 18:40 ` Andrii Nakryiko
2022-07-14 10:06 ` Alan Maguire
2022-07-15 7:07 ` Fedor Tokarev
2022-07-25 7:41 ` Alan Maguire
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YsyZY/tFm3hi5srl@krava \
--to=olsajiri@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=ftokarev@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox