Skip to contentSkip to conversation

libbpf: fix another __u64 cast in printf

PATCH Applied Andrii Nakryiko 2 participants 3 messages Sep 4, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 libbpf: fix another __u64 cast in printf

Another issue of __u64 needing either %lu or %llu, depending on the architecture. Fix with cast to unsigned long long.

Fixes 7e06aad52929 ("libbpf: Add multi-prog section support for struct_ops")
---
 tools/lib/bpf/libbpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/libbpf.c +1 -1
index 47b43c13eee5..53be32a2b9fc 100644
@@ -8224,7 +8224,7 @@ static int bpf_object__collect_st_ops_relos(struct bpf_object *obj,
 		}
 		if (sym.st_value % BPF_INSN_SZ) {
 			pr_warn("struct_ops reloc %s: invalid target program offset %llu\n",
-				map->name, (__u64)sym.st_value);
+				map->name, (unsigned long long)sym.st_value);
 			return -LIBBPF_ERRNO__FORMAT;
 		}
 		insn_idx = sym.st_value / BPF_INSN_SZ;
Signature · 1 line
2.24.1
#1 lore raw

PATCH 2/2 libbpf: fix potential multiplication overflow

Detected by LGTM static analyze in Github repo, fix potential multiplication overflow before result is casted to size_t.

Fixes 8505e8709b5e ("libbpf: Implement generalized .BTF.ext func/line info adjustment")
---
 tools/lib/bpf/libbpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/libbpf.c +1 -1
index 53be32a2b9fc..550950eb1860 100644
@@ -5802,7 +5802,7 @@ static int adjust_prog_btf_ext_info(const struct bpf_object *obj,
 		/* append func/line info of a given (sub-)program to the main
 		 * program func/line info
 		 */
-		old_sz = (*prog_rec_cnt) * ext_info->rec_size;
+		old_sz = (size_t)(*prog_rec_cnt) * ext_info->rec_size;
 		new_sz = old_sz + (copy_end - copy_start);
 		new_prog_info = realloc(*prog_info, new_sz);
 		if (!new_prog_info)
Signature · 1 line
2.24.1