[PATCH] libbpf: Change hash_combine parameters from long to unsigned long

Sidong Yang posted 1 patch 5 days, 20 hours ago
tools/lib/bpf/btf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] libbpf: Change hash_combine parameters from long to unsigned long
Posted by Sidong Yang 5 days, 20 hours ago
The hash_combine() could be trapped when compiled with sanitizer like "zig cc"
or clang with signed-integer-overflow option. This patch parameters and return
type to unsigned long to remove the potential overflow.

Signed-off-by: Sidong Yang <sidong.yang@furiosa.ai>
---
 tools/lib/bpf/btf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 8befb8103e32..12468ae0d573 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -3548,7 +3548,7 @@ struct btf_dedup {
 	struct strset *strs_set;
 };
 
-static long hash_combine(long h, long value)
+static unsigned long hash_combine(unsigned long h, unsigned long value)
 {
 	return h * 31 + value;
 }
-- 
2.42.0
Re: [PATCH] libbpf: Change hash_combine parameters from long to unsigned long
Posted by Yonghong Song 5 days, 10 hours ago


On 11/16/24 12:10 AM, Sidong Yang wrote:
> The hash_combine() could be trapped when compiled with sanitizer like "zig cc"
> or clang with signed-integer-overflow option. This patch parameters and return
> type to unsigned long to remove the potential overflow.
>
> Signed-off-by: Sidong Yang <sidong.yang@furiosa.ai>

Acked-by: Yonghong Song <yonghong.song@linux.dev>