* [PATCH] bpf: strnchr not suitable for getting NUL-terminator
@ 2024-04-10 0:33 Edward Adam Davis
2024-04-10 15:09 ` Yonghong Song
0 siblings, 1 reply; 3+ messages in thread
From: Edward Adam Davis @ 2024-04-10 0:33 UTC (permalink / raw)
To: bpf
Cc: andrii, ast, daniel, haoluo, john.fastabend, jolsa, kpsingh,
linux-kernel, martin.lau, sdf, song, syzkaller-bugs,
yonghong.song
The strnchr() is not suitable for obtaining the end of a string with a length
exceeding 1 and ending with a NUL character.
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;
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] bpf: strnchr not suitable for getting NUL-terminator
2024-04-10 0:33 [PATCH] bpf: strnchr not suitable for getting NUL-terminator Edward Adam Davis
@ 2024-04-10 15:09 ` Yonghong Song
2024-04-11 11:05 ` Edward Adam Davis
0 siblings, 1 reply; 3+ messages in thread
From: Yonghong Song @ 2024-04-10 15:09 UTC (permalink / raw)
To: Edward Adam Davis, bpf
Cc: andrii, ast, daniel, haoluo, john.fastabend, jolsa, kpsingh,
linux-kernel, martin.lau, sdf, song, syzkaller-bugs
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;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] bpf: strnchr not suitable for getting NUL-terminator
2024-04-10 15:09 ` Yonghong Song
@ 2024-04-11 11:05 ` Edward Adam Davis
0 siblings, 0 replies; 3+ messages in thread
From: Edward Adam Davis @ 2024-04-11 11:05 UTC (permalink / raw)
To: yonghong.song
Cc: andrii, ast, bpf, daniel, eadavis, haoluo, john.fastabend, jolsa,
kpsingh, linux-kernel, martin.lau, sdf, song, syzkaller-bugs
> > 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.
My mistake, strnchr() work well.
>
> >
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-04-11 11:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-10 0:33 [PATCH] bpf: strnchr not suitable for getting NUL-terminator Edward Adam Davis
2024-04-10 15:09 ` Yonghong Song
2024-04-11 11:05 ` Edward Adam Davis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox