From 8de5d2014a87d58d389eb8400f619d1b1fa3abe7 Mon Sep 17 00:00:00 2001 From: Matthias Baesken Date: Thu, 6 Jun 2024 12:27:26 +0000 Subject: [PATCH] 8332865: ubsan: os::attempt_reserve_memory_between reports overflow Reviewed-by: stuefe, clanger --- src/hotspot/share/runtime/os.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/hotspot/share/runtime/os.cpp b/src/hotspot/share/runtime/os.cpp index e7fed633c45..bdf93e1d3b4 100644 --- a/src/hotspot/share/runtime/os.cpp +++ b/src/hotspot/share/runtime/os.cpp @@ -1935,7 +1935,11 @@ char* os::attempt_reserve_memory_between(char* min, char* max, size_t bytes, siz return nullptr; // overflow } - char* const hi_att = align_down(MIN2(max, absolute_max) - bytes, alignment_adjusted); + char* const hi_end = MIN2(max, absolute_max); + if ((uintptr_t)hi_end < bytes) { + return nullptr; // no need to go on + } + char* const hi_att = align_down(hi_end - bytes, alignment_adjusted); if (hi_att > max) { return nullptr; // overflow }