Skip to content

Commit ebd8528

Browse files
author
Vladimir Kozlov
committed
8358289: [asan] runtime/cds/appcds/aotCode/AOTCodeFlags.java reports heap-buffer-overflow in ArchiveBuilder
Reviewed-by: shade, iklam, asmehra
1 parent 939521b commit ebd8528

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/hotspot/share/runtime/sharedRuntime.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,10 +2199,11 @@ class AdapterFingerPrint : public MetaspaceObj {
21992199
}
22002200

22012201
// Private construtor. Use allocate() to get an instance.
2202-
AdapterFingerPrint(int total_args_passed, BasicType* sig_bt) {
2202+
AdapterFingerPrint(int total_args_passed, BasicType* sig_bt, int len) {
22032203
int* data = data_pointer();
22042204
// Pack the BasicTypes with 8 per int
2205-
_length = length(total_args_passed);
2205+
assert(len == length(total_args_passed), "sanity");
2206+
_length = len;
22062207
int sig_index = 0;
22072208
for (int index = 0; index < _length; index++) {
22082209
int value = 0;
@@ -2217,16 +2218,15 @@ class AdapterFingerPrint : public MetaspaceObj {
22172218

22182219
// Call deallocate instead
22192220
~AdapterFingerPrint() {
2220-
FreeHeap(this);
2221+
ShouldNotCallThis();
22212222
}
22222223

22232224
static int length(int total_args) {
22242225
return (total_args + (_basic_types_per_int-1)) / _basic_types_per_int;
22252226
}
22262227

2227-
static int compute_size(int total_args_passed, BasicType* sig_bt) {
2228-
int len = length(total_args_passed);
2229-
return sizeof(AdapterFingerPrint) + (len * sizeof(int));
2228+
static int compute_size_in_words(int len) {
2229+
return (int)heap_word_size(sizeof(AdapterFingerPrint) + (len * sizeof(int)));
22302230
}
22312231

22322232
// Remap BasicTypes that are handled equivalently by the adapters.
@@ -2289,12 +2289,15 @@ class AdapterFingerPrint : public MetaspaceObj {
22892289

22902290
public:
22912291
static AdapterFingerPrint* allocate(int total_args_passed, BasicType* sig_bt) {
2292-
int size_in_bytes = compute_size(total_args_passed, sig_bt);
2293-
return new (size_in_bytes) AdapterFingerPrint(total_args_passed, sig_bt);
2292+
int len = length(total_args_passed);
2293+
int size_in_bytes = BytesPerWord * compute_size_in_words(len);
2294+
AdapterFingerPrint* afp = new (size_in_bytes) AdapterFingerPrint(total_args_passed, sig_bt, len);
2295+
assert((afp->size() * BytesPerWord) == size_in_bytes, "should match");
2296+
return afp;
22942297
}
22952298

22962299
static void deallocate(AdapterFingerPrint* fp) {
2297-
fp->~AdapterFingerPrint();
2300+
FreeHeap(fp);
22982301
}
22992302

23002303
int value(int index) {
@@ -2418,7 +2421,7 @@ class AdapterFingerPrint : public MetaspaceObj {
24182421

24192422
// methods required by virtue of being a MetaspaceObj
24202423
void metaspace_pointers_do(MetaspaceClosure* it) { return; /* nothing to do here */ }
2421-
int size() const { return (int)heap_word_size(sizeof(AdapterFingerPrint) + (_length * sizeof(int))); }
2424+
int size() const { return compute_size_in_words(_length); }
24222425
MetaspaceObj::Type type() const { return AdapterFingerPrintType; }
24232426

24242427
static bool equals(AdapterFingerPrint* const& fp1, AdapterFingerPrint* const& fp2) {

src/hotspot/share/runtime/sharedRuntime.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ class AdapterHandlerEntry : public MetaspaceObj {
711711
// Dummy argument is used to avoid C++ warning about using
712712
// deleted opearator MetaspaceObj::delete().
713713
void* operator new(size_t size, size_t dummy) throw() {
714+
assert(size == BytesPerWord * heap_word_size(sizeof(AdapterHandlerEntry)), "should match");
714715
void* p = AllocateHeap(size, mtCode);
715716
memset(p, 0, size);
716717
return p;

0 commit comments

Comments
 (0)