Skip to content

Commit 0735dc2

Browse files
author
David Holmes
committed
8362846: Windows error reporting for dll_load doesn't check for a null buffer
8362954: Missing error buffer null check in os::dll_load on Linux/BSD Reviewed-by: mgronlun, kbarrett
1 parent 79f9d8d commit 0735dc2

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

src/hotspot/os/bsd/os_bsd.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,10 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
11101110
if (result != nullptr) {
11111111
return result;
11121112
}
1113-
1113+
if (ebuf == nullptr || ebuflen < 1) {
1114+
// no error reporting requested
1115+
return nullptr;
1116+
}
11141117
Events::log_dll_message(nullptr, "Loading shared library %s failed, %s", filename, error_report);
11151118
log_info(os)("shared library load of %s failed, %s", filename, error_report);
11161119
int diag_msg_max_length=ebuflen-strlen(ebuf);

src/hotspot/os/linux/os_linux.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,11 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
16851685
return result;
16861686
}
16871687

1688+
if (ebuf == nullptr || ebuflen < 1) {
1689+
// no error reporting requested
1690+
return nullptr;
1691+
}
1692+
16881693
Elf32_Ehdr elf_head;
16891694
size_t prefix_len = strlen(ebuf);
16901695
ssize_t diag_msg_max_length = ebuflen - prefix_len;

src/hotspot/os/windows/os_windows.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,12 @@ void * os::dll_load(const char *name, char *ebuf, int ebuflen) {
17291729
log_info(os)("shared library load of %s was successful", name);
17301730
return result;
17311731
}
1732+
1733+
if (ebuf == nullptr || ebuflen < 1) {
1734+
// no error reporting requested
1735+
return nullptr;
1736+
}
1737+
17321738
DWORD errcode = GetLastError();
17331739
// Read system error message into ebuf
17341740
// It may or may not be overwritten below (in the for loop and just above)
@@ -2261,6 +2267,8 @@ void os::jvm_path(char *buf, jint buflen) {
22612267
// from src/windows/hpi/src/system_md.c
22622268

22632269
size_t os::lasterror(char* buf, size_t len) {
2270+
assert(buf != nullptr && len > 0, "invalid buffer passed");
2271+
22642272
DWORD errval;
22652273

22662274
if ((errval = GetLastError()) != 0) {

test/hotspot/gtest/runtime/test_os.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,3 +1181,9 @@ TEST_VM(os, map_memory_to_file_aligned) {
11811181
}
11821182

11831183
#endif // !defined(_AIX)
1184+
1185+
TEST_VM(os, dll_load_null_error_buf) {
1186+
// This should not crash.
1187+
void* lib = os::dll_load("NoSuchLib", nullptr, 0);
1188+
ASSERT_NULL(lib);
1189+
}

0 commit comments

Comments
 (0)