From af8fd8c8d8feeb4e515bdccb0db7e629a51e1b44 Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Sat, 10 Oct 2020 20:08:33 +0300 Subject: [PATCH] utils: build_id: fix ubsan false positive on pointer arithmetic get_nt_build_id() constructs a pointer by adding a base and an offset, but if the base happens to be zero, that is undefined under C++ rules (altough legal ELF). Fix by performing the addition on integers, and only then casting to a pointer. Closes #7379 --- utils/build_id.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/build_id.cc b/utils/build_id.cc index 32c1f029de..ac0c5ca8d0 100644 --- a/utils/build_id.cc +++ b/utils/build_id.cc @@ -20,7 +20,7 @@ static const Elf64_Nhdr* get_nt_build_id(dl_phdr_info* info) { continue; } - auto* p = reinterpret_cast(base) + h->p_vaddr; + auto* p = reinterpret_cast(base + h->p_vaddr); auto* e = p + h->p_memsz; while (p != e) { const auto* n = reinterpret_cast(p);