JDK-8362846 : Windows error reporting for dll_load doesn't check for a null buffer
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 8
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows
  • Submitted: 2025-07-21
  • Updated: 2025-07-25
  • Resolved: 2025-07-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 26
26 b08Fixed
Related Reports
Causes :  
Relates :  
Description
Library loading is performed by:

void * os::dll_load(const char *name, char *ebuf, int ebuflen) 

where the `ebuf` buffer is used for producing error information if the loading fails. However on Windows the `ebuf` value is never checked for null but is used unconditionally e.g.

 // Read system error message into ebuf
  // It may or may not be overwritten below (in the for loop and just above)
  lasterror(ebuf, (size_t) ebuflen);
  ebuf[ebuflen - 1] = '\0';
  Events::log_dll_message(nullptr, "Loading shared library %s failed, error code %lu", name, errcode);
  log_info(os)("shared library load of %s failed, error code %lu", name, errcode);

  if (errcode == ERROR_MOD_NOT_FOUND) {
    strncpy(ebuf, "Can't find dependent libraries", ebuflen - 1);
    ebuf[ebuflen - 1] = '\0';
    JFR_ONLY(load_event.set_error_msg(ebuf);)
    return nullptr;
  }

Whilst it seems a little odd to pass a null buffer and skip error reporting, that is what the JFR code does when loading some of its libraries:

void IphlpDll::initialize(void) {
  _hModule = os::win32::load_Windows_dll("iphlpapi.dll", nullptr, 0);

void PdhDll::initialize(void) {
  _hModule = os::win32::load_Windows_dll("pdh.dll", nullptr, 0);

The Posix code correctly handles a null buffer.

The code for this was added in JDK 6, but it was only in JDK 11 that JFR started passing the null buffers.
Comments
Changeset: 0735dc27 Branch: master Author: David Holmes <dholmes@openjdk.org> Date: 2025-07-23 00:36:35 +0000 URL: https://git.openjdk.org/jdk/commit/0735dc27c71de46896afd2f0f608319304a3d549
23-07-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/26420 Date: 2025-07-22 00:31:39 +0000
22-07-2025

Sample crash report if the library loading fails: # # A fatal error has been detected by the Java Runtime Environment: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007fffdf628b8b, pid=4876, tid=9900 # # JRE version: Java(TM) SE Runtime Environment (26.0) (fastdebug build 26-internal-2025-07-20-2206340.david.holmes.jdk-dev4.git) # Java VM: Java HotSpot(TM) 64-Bit Server VM (fastdebug 26-internal-2025-07-20-2206340.david.holmes.jdk-dev4.git, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, windows-amd64) # Problematic frame: # V [jvm.dll+0xde8b8b] os::dll_load+0xfb # # Core dump will be written. Default location: C:\sb\prod\1753051064\testoutput\test-support\jtreg_open_test_jdk_jdk_jfr\scratch\4_1\hs_err_pid4876.mdmp # # JFR recording file will be written. Location: C:\sb\prod\1753051064\testoutput\test-support\jtreg_open_test_jdk_jdk_jfr\scratch\4_1\hs_err_pid4876.jfr # # If you would like to submit a bug report, please visit: # https://bugreport.java.com/bugreport/crash.jsp # The crash happened outside the Java Virtual Machine in native code. # See problematic frame for where to report the bug. # --------------- S U M M A R Y ------------ Command Line: -Dtest.vm.opts=-Xmx768m -XX:MaxRAMPercentage=4.16667 -Dtest.boot.jdk=c:\ade\mesos\work_dir\jib-master\install\jdk\24\36\bundles\windows-x64\jdk-24_windows-x64_bin.zip\jdk-24 -Djava.io.tmpdir=c:\sb\prod\1753051064\testoutput\test-support\jtreg_open_test_jdk_jdk_jfr\tmp -XX:+CreateCoredumpOnCrash -ea -esa -Dtest.tool.vm.opts=-J-Xmx768m -J-XX:MaxRAMPercentage=4.16667 -J-Dtest.boot.jdk=c:\ade\mesos\work_dir\jib-master\install\jdk\24\36\bundles\windows-x64\jdk-24_windows-x64_bin.zip\jdk-24 -J-Djava.io.tmpdir=c:\sb\prod\1753051064\testoutput\test-support\jtreg_open_test_jdk_jdk_jfr\tmp -J-XX:+CreateCoredumpOnCrash -J-ea -J-esa -Dtest.compiler.opts= -Dtest.java.opts= -Dtest.jdk=c:\ade\mesos\work_dir\jib-master\install\2025-07-20-2206340.david.holmes.jdk-dev4.git\windows-x64-debug.jdk\jdk-26\fastdebug -Dcompile.jdk=c:\ade\mesos\work_dir\jib-master\install\2025-07-20-2206340.david.holmes.jdk-dev4.git\windows-x64-debug.jdk\jdk-26\fastdebug -Dtest.timeout.factor=4.0 -Dtest.nativepath=c:\ade\mesos\work_dir\jib-master\install\2025-07-20-2206340.david.holmes.jdk-dev4.git\windows-x64-debug.test\jdk\jtreg\native -Dtest.root=C:\ade\mesos\work_dir\jib-master\install\2025-07-20-2206340.david.holmes.jdk-dev4.git\src.full\open\test\jdk -Dtest.name=jdk/jfr/tool/TestView.java -Dtest.verbose=Verbose[p=BRIEF,f=FULL,e=FULL,t=true,m=false] -Dtest.file=C:\ade\mesos\work_dir\jib-master\install\2025-07-20-2206340.david.holmes.jdk-dev4.git\src.full\open\test\jdk\jdk\jfr\tool\TestView.java -Dtest.main.class=jdk.jfr.tool.TestView -Dtest.src=C:\ade\mesos\work_dir\jib-master\install\2025-07-20-2206340.david.holmes.jdk-dev4.git\src.full\open\test\jdk\jdk\jfr\tool -Dtest.src.path=C:\ade\mesos\work_dir\jib-master\install\2025-07-20-2206340.david.holmes.jdk-dev4.git\src.full\open\test\jdk\jdk\jfr\tool;C:\ade\mesos\work_dir\jib-master\install\2025-07-20-2206340.david.holmes.jdk-dev4.git\src.full\open\test\lib;C:\ade\mesos\work_dir\jib-master\install\2025-07-20-2206340.david.holmes.jdk-dev4.git\src.full\open\test\jdk -Dtest.classes=C:\sb\prod\1753051064\testoutput\test-support\jtreg_open_test_jdk_jdk_jfr\classes\2\jdk\jfr\tool\TestView.d -Dtest.class.path=C:\sb\prod\1753051064\testoutput\test-support\jtreg_open_test_jdk_jdk_jfr\classes\2\jdk\jfr\tool\TestView.d;C:\sb\prod\1753051064\testoutput\test-support\jtreg_open_test_jdk_jdk_jfr\classes\2\test\lib;C:\sb\prod\1753051064\testoutput\test-support\jtreg_open_test_jdk_jdk_jfr\classes\2\test\jdk -Dtest.class.path.prefix=C:\sb\prod\1753051064\testoutput\test-support\jtreg_open_test_jdk_jdk_jfr\classes\2\jdk\jfr\tool\TestView.d;C:\ade\mesos\work_dir\jib-master\install\2025-07-20-2206340.david.holmes.jdk-dev4.git\src.full\open\test\jdk\jdk\jfr\tool;C:\sb\prod\1753051064\testoutput\test-support\jtreg_open_test_jdk_jdk_jfr\classes\2\test\lib;C:\sb\prod\1753051064\testoutput\test-support\jtreg_open_test_jdk_jdk_jfr\classes\2\test\jdk -Dtest.modules=jdk.jfr --add-modules=jdk.jfr -Xmx768m -XX:MaxRAMPercentage=4.16667 -Dtest.boot.jdk=c:\ade\mesos\work_dir\jib-master\install\jdk\24\36\bundles\windows-x64\jdk-24_windows-x64_bin.zip\jdk-24 -Djava.io.tmpdir=c:\sb\prod\1753051064\testoutput\test-support\jtreg_open_test_jdk_jdk_jfr\tmp -XX:+CreateCoredumpOnCrash -ea -esa -Djava.library.path=c:\ade\mesos\work_dir\jib-master\install\2025-07-20-2206340.david.holmes.jdk-dev4.git\windows-x64-debug.test\jdk\jtreg\native -XX:-ExplicitGCInvokesConcurrent -XX:-DisableExplicitGC -XX:+UseG1GC com.sun.javatest.regtest.agent.MainWrapper C:\sb\prod\1753051064\testoutput\test-support\jtreg_open_test_jdk_jdk_jfr\jdk\jfr\tool\TestView.d\main.0.jta Host: AMD EPYC 9J14 96-Core Processor , 12 cores, 23G, Windows Server 2022 , 64 bit Build 20348 (10.0.20348.3451) Time: Sun Jul 20 23:54:20 2025 /GM elapsed time: 3.682881 seconds (0d 0h 0m 3s) --------------- T H R E A D --------------- Current thread (0x0000021fbd37c770): JavaThread "JFR Periodic Tasks" daemon [_thread_in_native, id=9900, stack(0x00000064c5a00000,0x00000064c5b00000) (1024K)] Stack: [0x00000064c5a00000,0x00000064c5b00000], sp=0x00000064c5afe6e0, free space=1017k Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) V [jvm.dll+0xde8b8b] os::dll_load+0xfb (os_windows.cpp:1737) V [jvm.dll+0xdec6c2] os::win32::load_Windows_dll+0xf2 (os_windows.cpp:4173) V [jvm.dll+0xe2c40e] PdhDll::PdhAttach+0x4e (pdh_interface.cpp:109) V [jvm.dll+0xde5a02] pdh_acquire+0x52 (os_perf_windows.cpp:1065) V [jvm.dll+0xde43e4] CPUPerformanceInterface::CPUPerformance::initialize+0x24 (os_perf_windows.cpp:1098) V [jvm.dll+0x971fa2] JfrOSInterface::JfrOSInterfaceImpl::cpu_perf_interface+0x62 (jfrOSInterface.cpp:120) V [jvm.dll+0x971f12] JfrOSInterface::cpu_loads_process+0x22 (jfrOSInterface.cpp:244) V [jvm.dll+0x978ccf] JfrPeriodicEventSet::requestCPULoad+0x11f (jfrPeriodic.cpp:206) V [jvm.dll+0x962168] jfr_emit_event+0x88 (jfrJniMethod.cpp:254) C 0x0000021faaaef7d8 (no source info available) The last pc belongs to native method entry point (kind = native) (printed below). Java frames: (J=compiled Java code, j=interpreted, Vv=VM code) j jdk.jfr.internal.JVM.emitEvent(JJJ)Z+0 jdk.jfr@26-internal j jdk.jfr.internal.periodic.JVMEventTask.execute(JLjdk/jfr/internal/periodic/PeriodicType;)V+21 jdk.jfr@26-internal j jdk.jfr.internal.periodic.PeriodicTask.run(JLjdk/jfr/internal/periodic/PeriodicType;)V+15 jdk.jfr@26-internal j jdk.jfr.internal.periodic.PeriodicEvents.doPeriodic()J+263 jdk.jfr@26-internal j jdk.jfr.internal.PlatformRecorder.periodicTask()V+47 jdk.jfr@26-internal j jdk.jfr.internal.PlatformRecorder.lambda$startDiskMonitor$0()V+1 jdk.jfr@26-internal j jdk.jfr.internal.PlatformRecorder$$Lambda+0x000000008a06c918.run()V+4 jdk.jfr@26-internal j java.lang.Thread.runWith(Ljava/lang/Object;Ljava/lang/Runnable;)V+5 java.base@26-internal j java.lang.Thread.run()V+19 java.base@26-internal v ~StubRoutines::Stub Generator call_stub_stub 0x0000021faaae1a52 siginfo: EXCEPTION_ACCESS_VIOLATION (0xc0000005), writing address 0xffffffffffffffff
21-07-2025