Skip to content

Commit 083416d

Browse files
Wang Huangmiaozhuojun
authored and
Hamlin Li
committed
8267130: Memory Overflow in Disassembler::load_library
Co-authored-by: Wang Huang <whuang@openjdk.org> Co-authored-by: Miao Zhuojun <mouzhuojun@huawei.com> Reviewed-by: neliasso, mli
1 parent 9d305b9 commit 083416d

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

src/hotspot/share/compiler/disassembler.cpp

+24-12
Original file line numberDiff line numberDiff line change
@@ -804,27 +804,39 @@ bool Disassembler::load_library(outputStream* st) {
804804
// 4. hsdis-<arch>.so (using LD_LIBRARY_PATH)
805805
if (jvm_offset >= 0) {
806806
// 1. <home>/lib/<vm>/libhsdis-<arch>.so
807-
strcpy(&buf[jvm_offset], hsdis_library_name);
808-
strcat(&buf[jvm_offset], os::dll_file_extension());
809-
if (Verbose) st->print_cr("Trying to load: %s", buf);
810-
_library = os::dll_load(buf, ebuf, sizeof ebuf);
811-
if (_library == NULL && lib_offset >= 0) {
812-
// 2. <home>/lib/<vm>/hsdis-<arch>.so
813-
strcpy(&buf[lib_offset], hsdis_library_name);
814-
strcat(&buf[lib_offset], os::dll_file_extension());
807+
if (jvm_offset + strlen(hsdis_library_name) + strlen(os::dll_file_extension()) < JVM_MAXPATHLEN) {
808+
strcpy(&buf[jvm_offset], hsdis_library_name);
809+
strcat(&buf[jvm_offset], os::dll_file_extension());
815810
if (Verbose) st->print_cr("Trying to load: %s", buf);
816811
_library = os::dll_load(buf, ebuf, sizeof ebuf);
812+
} else {
813+
if (Verbose) st->print_cr("Try to load hsdis library failed: the length of path is beyond the OS limit");
814+
}
815+
if (_library == NULL && lib_offset >= 0) {
816+
// 2. <home>/lib/<vm>/hsdis-<arch>.so
817+
if (lib_offset + strlen(hsdis_library_name) + strlen(os::dll_file_extension()) < JVM_MAXPATHLEN) {
818+
strcpy(&buf[lib_offset], hsdis_library_name);
819+
strcat(&buf[lib_offset], os::dll_file_extension());
820+
if (Verbose) st->print_cr("Trying to load: %s", buf);
821+
_library = os::dll_load(buf, ebuf, sizeof ebuf);
822+
} else {
823+
if (Verbose) st->print_cr("Try to load hsdis library failed: the length of path is beyond the OS limit");
824+
}
817825
}
818826
if (_library == NULL && lib_offset > 0) {
819827
// 3. <home>/lib/hsdis-<arch>.so
820828
buf[lib_offset - 1] = '\0';
821829
const char* p = strrchr(buf, *os::file_separator());
822830
if (p != NULL) {
823831
lib_offset = p - buf + 1;
824-
strcpy(&buf[lib_offset], hsdis_library_name);
825-
strcat(&buf[lib_offset], os::dll_file_extension());
826-
if (Verbose) st->print_cr("Trying to load: %s", buf);
827-
_library = os::dll_load(buf, ebuf, sizeof ebuf);
832+
if (lib_offset + strlen(hsdis_library_name) + strlen(os::dll_file_extension()) < JVM_MAXPATHLEN) {
833+
strcpy(&buf[lib_offset], hsdis_library_name);
834+
strcat(&buf[lib_offset], os::dll_file_extension());
835+
if (Verbose) st->print_cr("Trying to load: %s", buf);
836+
_library = os::dll_load(buf, ebuf, sizeof ebuf);
837+
} else {
838+
if (Verbose) st->print_cr("Try to load hsdis library failed: the length of path is beyond the OS limit");
839+
}
828840
}
829841
}
830842
}

0 commit comments

Comments
 (0)