RFR 8074368: ThreadMXBean.getThreadInfo() corrupts memory when called with empty array for thread ids

Jaroslav Bachorik jaroslav.bachorik at oracle.com
Fri Apr 3 14:31:03 UTC 2015


Please, review the following change

Issue : https://bugs.openjdk.java.net/browse/JDK-8074368
Webrev: http://cr.openjdk.java.net/~jbachorik/8074368/webrev.00

Invoking ThreadMXBean.getThreadInfo(long[] ids, int maxdepth) with an 
empty array for 'ids' and positive number for 'maxdepth' can result in 
memory corruption. Basically, the native routine (VM_ThreadDump) 
considers the empty ids array as a signal to process all the available 
threads and put their information to the pre-allocated array while the 
pre-allocated array's size is 0.

The solution is to modify 'management.cpp' and check for 'num_threads' 
before actually attempting to do the thread dump.

As a defense-in-depth the ThreadMXBean.getThreadInfo(*) methods are 
modified to adhere to their specification and return 'an array of the 
ThreadInfo objects, each containing information about a thread whose ID 
is in the corresponding element of the input array of IDs' - meaning 
that an empty ids array will result in an empty ThreadInfo array.

Thanks,

-JB-


More information about the serviceability-dev mailing list