libbpf: Fix an unsigned < 0 bug
PATCH 1/1 libbpf: Fix an unsigned < 0 bug
Andrii reported a bug with the following information:
2859 if (enum64_placeholder_id == 0) {
2860 enum64_placeholder_id = btf__add_int(btf, "enum64_placeholder", 1, 0);
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
CID 394804: Control flow issues (
NO_EFFECT)
This less-than-zero comparison of an unsigned value is never true. "enum64_placeholder_id< 0U".
2861 if (enum64_placeholder_id < 0)
2862 return enum64_placeholder_id;
2863 ...
Here enum64_placeholder_id declared as '__u32' so enum64_placeholder_id < 0 is always false.
Declare enum64_placeholder_id as 'int' in order to capture the potential error properly.
--- tools/lib/bpf/libbpf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/libbpf.c +1 -1
@@ -2786,7 +2786,7 @@ static int bpf_object__sanitize_btf(struct bpf_object *obj, struct btf *btf)bool has_decl_tag =kernel_supports (obj,FEAT_BTF_DECL_TAG );bool has_type_tag =kernel_supports (obj,FEAT_BTF_TYPE_TAG );bool has_enum64 =kernel_supports (obj,FEAT_BTF_ENUM64 ); -__u32 enum64_placeholder_id =0 ; +int enum64_placeholder_id =0 ;struct btf_type *t;int i, j, vlen;
Signature · 1 line
2.30.2
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Quoted 10 lines · On Sun, 12 Jun 2022 22:43:14 -0700 you wrote:
Andrii reported a bug with the following information:
2859 if (enum64_placeholder_id== 0) {
2860enum64_placeholder_id=btf__add_int(btf, "enum64_placeholder", 1, 0);Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
CID 394804: Control flow issues (
NO_EFFECT)
This less-than-zero comparison of an unsigned value is never true. "enum64_placeholder_id< 0U".2861 if (
enum64_placeholder_id< 0)
2862 returnenum64_placeholder_id;
2863 ...[...]
Here is the summary with links:
- [bpf-next] libbpf: Fix an unsigned < 0 bug
https://git.kernel.org/bpf/bpf-next/c/c49a44b39b31
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html