From: Yonghong Song <yonghong.song@linux.dev>
To: Edward Adam Davis <eadavis@qq.com>, bpf@vger.kernel.org
Cc: andrii@kernel.org, ast@kernel.org, daniel@iogearbox.net,
haoluo@google.com, john.fastabend@gmail.com, jolsa@kernel.org,
kpsingh@kernel.org, linux-kernel@vger.kernel.org,
martin.lau@linux.dev, sdf@google.com, song@kernel.org,
syzkaller-bugs@googlegroups.com
Subject: Re: [PATCH] bpf: strnchr not suitable for getting NUL-terminator
Date: Wed, 10 Apr 2024 08:09:45 -0700 [thread overview]
Message-ID: <4bfc3494-a3e9-4b4c-9d93-fa1049a10235@linux.dev> (raw)
In-Reply-To: <tencent_EC72CD3879FA6F102FC56E4495F0E822EC0A@qq.com>
On 4/9/24 5:33 PM, Edward Adam Davis wrote:
> The strnchr() is not suitable for obtaining the end of a string with a length
> exceeding 1 and ending with a NUL character.
Could you give more detailed explanation with specific examples? I think
strnchr() does the right thing here. Note that if fmt is not NULL,
strnchrnul() never returns NULL pointer so in the change below,
'if (!fmt_end)' will be always false.
>
> Signed-off-by: Edward Adam Davis <eadavis@qq.com>
> ---
> kernel/bpf/helpers.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
> index 449b9a5d3fe3..07490eba24fe 100644
> --- a/kernel/bpf/helpers.c
> +++ b/kernel/bpf/helpers.c
> @@ -826,7 +826,7 @@ int bpf_bprintf_prepare(char *fmt, u32 fmt_size, const u64 *raw_args,
> u64 cur_arg;
> char fmt_ptype, cur_ip[16], ip_spec[] = "%pXX";
>
> - fmt_end = strnchr(fmt, fmt_size, 0);
> + fmt_end = strnchrnul(fmt, fmt_size, 0);
> if (!fmt_end)
> return -EINVAL;
> fmt_size = fmt_end - fmt;
next prev parent reply other threads:[~2024-04-10 15:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-10 0:33 [PATCH] bpf: strnchr not suitable for getting NUL-terminator Edward Adam Davis
2024-04-10 15:09 ` Yonghong Song [this message]
2024-04-11 11:05 ` Edward Adam Davis
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=4bfc3494-a3e9-4b4c-9d93-fa1049a10235@linux.dev \
--to=yonghong.song@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eadavis@qq.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=syzkaller-bugs@googlegroups.com \
/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