提交 339ef484 编写于 作者: S shshahma

8157548: JVM crashes sometimes while starting

Summary: Behavior of strncmp may be unexpected if char buffers[s] is[are] not null terminated and buffer size is smaller than the length n. Added check to avoid this scenario.
Reviewed-by: dholmes, iklam
上级 f2ecef3c
...@@ -1084,15 +1084,18 @@ Klass* SystemDictionary::resolve_from_stream(Symbol* class_name, ...@@ -1084,15 +1084,18 @@ Klass* SystemDictionary::resolve_from_stream(Symbol* class_name,
THREAD); THREAD);
const char* pkg = "java/"; const char* pkg = "java/";
size_t pkglen = strlen(pkg);
if (!HAS_PENDING_EXCEPTION && if (!HAS_PENDING_EXCEPTION &&
!class_loader.is_null() && !class_loader.is_null() &&
parsed_name != NULL && parsed_name != NULL &&
!strncmp((const char*)parsed_name->bytes(), pkg, strlen(pkg))) { parsed_name->utf8_length() >= (int)pkglen &&
!strncmp((const char*)parsed_name->bytes(), pkg, pkglen)) {
// It is illegal to define classes in the "java." package from // It is illegal to define classes in the "java." package from
// JVM_DefineClass or jni_DefineClass unless you're the bootclassloader // JVM_DefineClass or jni_DefineClass unless you're the bootclassloader
ResourceMark rm(THREAD); ResourceMark rm(THREAD);
char* name = parsed_name->as_C_string(); char* name = parsed_name->as_C_string();
char* index = strrchr(name, '/'); char* index = strrchr(name, '/');
assert(index != NULL, "must be");
*index = '\0'; // chop to just the package name *index = '\0'; // chop to just the package name
while ((index = strchr(name, '/')) != NULL) { while ((index = strchr(name, '/')) != NULL) {
*index = '.'; // replace '/' with '.' in package name *index = '.'; // replace '/' with '.' in package name
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册