@@ -804,27 +804,39 @@ bool Disassembler::load_library(outputStream* st) {
804
804
// 4. hsdis-<arch>.so (using LD_LIBRARY_PATH)
805
805
if (jvm_offset >= 0 ) {
806
806
// 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 ());
815
810
if (Verbose) st->print_cr (" Trying to load: %s" , buf);
816
811
_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
+ }
817
825
}
818
826
if (_library == NULL && lib_offset > 0 ) {
819
827
// 3. <home>/lib/hsdis-<arch>.so
820
828
buf[lib_offset - 1 ] = ' \0 ' ;
821
829
const char * p = strrchr (buf, *os::file_separator ());
822
830
if (p != NULL ) {
823
831
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
+ }
828
840
}
829
841
}
830
842
}
0 commit comments