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.
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.
- caused by
-
JDK-6374419 Misleading error message if 32bit dll used together with 64 bit VM
-
- Closed
-
- relates to
-
JDK-8362954 Missing error buffer null check in os::dll_load on Linux/BSD
-
- Resolved
-
- links to
-
Commit(master) openjdk/jdk/0735dc27
-
Review(master) openjdk/jdk/26420