[foreign-memaccess+abi] RFR: 8294309: Downcall and Upcall unboxing code should reject heap segments
Jorn Vernee
jvernee at openjdk.org
Tue Oct 4 12:25:30 UTC 2022
On Tue, 4 Oct 2022 12:04:51 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> Recently I noticed that we don't check for heap segments anymore when unboxing memory segments to be passed to native code as addresses. This allows someone to pass a heap segment, which will be unboxed simply by calling `MemorySegment::address` which for heap segments returns the byte offset into the array. This is of course not a valid pointer.
>>
>> This patch changes the unboxing logic to reject heap segments with an `IllegalArgumentException`.
>
> src/java.base/share/classes/jdk/internal/foreign/abi/SharedUtils.java line 265:
>
>> 263:
>> 264: static long unboxSegment(MemorySegment segment) {
>> 265: if (segment instanceof HeapMemorySegmentImpl) {
>
> there's MemorySegment.isNative, which maybe is better?
Yeah, that works. It also includes mapped segments
-------------
PR: https://git.openjdk.org/panama-foreign/pull/737
More information about the panama-dev
mailing list