From 01312a002ba27bfbfebb9fde484ca34ebde0704c Mon Sep 17 00:00:00 2001 From: Tobias Holenstein Date: Fri, 10 Mar 2023 15:39:45 +0000 Subject: [PATCH] 8300821: UB: Applying non-zero offset to non-null pointer 0xfffffffffffffffe produced null pointer Reviewed-by: kvn, thartmann --- src/hotspot/share/asm/codeBuffer.cpp | 4 ++-- src/hotspot/share/code/relocInfo.cpp | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/hotspot/share/asm/codeBuffer.cpp b/src/hotspot/share/asm/codeBuffer.cpp index 785e49dcd83..f3b665220de 100644 --- a/src/hotspot/share/asm/codeBuffer.cpp +++ b/src/hotspot/share/asm/codeBuffer.cpp @@ -523,7 +523,7 @@ void CodeBuffer::finalize_oop_references(const methodHandle& mh) { for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { // pull code out of each section CodeSection* cs = code_section(n); - if (cs->is_empty()) continue; // skip trivial section + if (cs->is_empty() || !cs->has_locs()) continue; // skip trivial section RelocIterator iter(cs); while (iter.next()) { if (iter.type() == relocInfo::metadata_type) { @@ -791,7 +791,7 @@ void CodeBuffer::relocate_code_to(CodeBuffer* dest) const { for (int n = (int) SECT_FIRST; n < (int)SECT_LIMIT; n++) { // pull code out of each section const CodeSection* cs = code_section(n); - if (cs->is_empty()) continue; // skip trivial section + if (cs->is_empty() || !cs->has_locs()) continue; // skip trivial section CodeSection* dest_cs = dest->code_section(n); { // Repair the pc relative information in the code after the move RelocIterator iter(dest_cs); diff --git a/src/hotspot/share/code/relocInfo.cpp b/src/hotspot/share/code/relocInfo.cpp index 2048964da65..3394802f452 100644 --- a/src/hotspot/share/code/relocInfo.cpp +++ b/src/hotspot/share/code/relocInfo.cpp @@ -149,7 +149,8 @@ void RelocIterator::initialize(CompiledMethod* nm, address begin, address limit) RelocIterator::RelocIterator(CodeSection* cs, address begin, address limit) { initialize_misc(); - + assert((cs->locs_start() != nullptr) && (cs->locs_end() != nullptr) || + (cs->locs_start() == nullptr) && (cs->locs_end() == nullptr), "valid start and end pointer"); _current = cs->locs_start()-1; _end = cs->locs_end(); _addr = cs->start();