selftests/bpf: Fix incorrect parameters in NULL pointer checking
Subsystems (3)
PATCH 1/1 selftests/bpf: Fix incorrect parameters in NULL pointer checking
From: Hao Ge <[email protected]>
Smatch reported the following warning:
./tools/testing/selftests/bpf/testing_helpers.c:455 get_xlated_program()
warn: variable dereferenced before check 'buf' (see line 454)
It seems correct,so let's modify it based on it's suggestion.
Actually,commit b23ed4d74c4d ("selftests/bpf: Fix invalid pointer check in get_xlated_program()") fixed an issue in the test_verifier.c once,but it was reverted this time.
Let's solve this issue with the minimal changes possible.
--- tools/testing/selftests/bpf/testing_helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/testing_helpers.c +1 -1
@@ -451,7 +451,7 @@ int get_xlated_program(int fd_prog, struct bpf_insn **buf, __u32 *cnt) *cnt = xlated_prog_len / buf_element_size; *buf =calloc (*cnt, buf_element_size); -if (!buf) { +if (!*buf) {perror ("can't allocate xlated program buffer" );return -ENOMEM ; }
Signature · 1 line
2.25.1
Hi
I apologize for the confusion.
I mistakenly thought that my previous email (https://lore.kernel.org/all/[email protected]/)
didn't send due to network issues on my computer, so I resent it.
However, it seems that was not the case.
Please kindly disregard this patch as it is identical to the previous one.
I sincerely apologize for wasting everyone's time
Quoted 27 lines · Hao Ge
From: Hao Ge <[email protected]>
Smatch reported the following warning:
./tools/testing/selftests/bpf/testing_helpers.c:455get_xlated_program()
warn: variable dereferenced before check 'buf' (see line 454)It seems correct,so let's modify it based on it's suggestion.
Actually,commit
b23ed4d74c4d("selftests/bpf: Fix invalid pointer check inget_xlated_program()") fixed an issue in thetest_verifier.conce,but it was reverted this time.Let's solve this issue with the minimal changes possible.
Reported-by Dan Carpenter <[email protected]>Fixes b4b7a4099b8c ("selftests/bpf: Factor out get_xlated_program() helper")Signed-off-by Hao Ge <[email protected]>--- tools/testing/selftests/bpf/testing_helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/testing/selftests/bpf/testing_helpers.c +0
-0
tools/testing/selftests/bpf/testing_helpers.c int get_xlated_program(int fd_prog, struct bpf_insn **buf, __u32 *cnt) · line 457
Quoted 8 lines
tools/testing/selftests/bpf/testing_helpers.c +1
-1@@ -451,7 +451,7 @@ int get_xlated_program(int fd_prog, struct bpf_insn **buf, __u32 *cnt) *cnt = xlated_prog_len / buf_element_size; *buf =calloc (*cnt, buf_element_size); -if (!buf) { +if (!*buf) {perror ("can't allocate xlated program buffer" );return -ENOMEM ; }
Thanks
Best regards
Hao
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 9 lines · On Tue, 20 Aug 2024 10:36:22 +0800 you wrote:
From: Hao Ge <[email protected]>
Smatch reported the following warning:
./tools/testing/selftests/bpf/testing_helpers.c:455get_xlated_program()
warn: variable dereferenced before check 'buf' (see line 454)It seems correct,so let's modify it based on it's suggestion.
[...]
Here is the summary with links:
- selftests/bpf: Fix incorrect parameters in NULL pointer checking
https://git.kernel.org/bpf/bpf-next/c/c264487e5410
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html