8135195: VM Options file should not be limited to 1k in bytes
Change Arguments::parse_vm_options_file() to remove 1024 byte limit on the VM options file. Reviewed-by: dcubed, hseigel, gthornbr, dsamersoff, ddmitriev, coleenp
This commit is contained in:
parent
786cdcb65d
commit
8ff97188d3
@ -3711,8 +3711,6 @@ jint Arguments::parse_options_environment_variable(const char* name,
|
|||||||
return retcode;
|
return retcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int OPTION_BUFFER_SIZE = 1024;
|
|
||||||
|
|
||||||
jint Arguments::parse_vm_options_file(const char* file_name, ScopedVMInitArgs* vm_args) {
|
jint Arguments::parse_vm_options_file(const char* file_name, ScopedVMInitArgs* vm_args) {
|
||||||
// read file into buffer
|
// read file into buffer
|
||||||
int fd = ::open(file_name, O_RDONLY);
|
int fd = ::open(file_name, O_RDONLY);
|
||||||
@ -3723,8 +3721,24 @@ jint Arguments::parse_vm_options_file(const char* file_name, ScopedVMInitArgs* v
|
|||||||
return JNI_ERR;
|
return JNI_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct stat stbuf;
|
||||||
|
int retcode = os::stat(file_name, &stbuf);
|
||||||
|
if (retcode != 0) {
|
||||||
|
jio_fprintf(defaultStream::error_stream(),
|
||||||
|
"Could not stat options file '%s'\n",
|
||||||
|
file_name);
|
||||||
|
os::close(fd);
|
||||||
|
return JNI_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stbuf.st_size == 0) {
|
||||||
|
// tell caller there is no option data and that is ok
|
||||||
|
os::close(fd);
|
||||||
|
return JNI_OK;
|
||||||
|
}
|
||||||
|
|
||||||
// '+ 1' for NULL termination even with max bytes
|
// '+ 1' for NULL termination even with max bytes
|
||||||
int bytes_alloc = OPTION_BUFFER_SIZE + 1;
|
size_t bytes_alloc = stbuf.st_size + 1;
|
||||||
|
|
||||||
char *buf = NEW_C_HEAP_ARRAY_RETURN_NULL(char, bytes_alloc, mtInternal);
|
char *buf = NEW_C_HEAP_ARRAY_RETURN_NULL(char, bytes_alloc, mtInternal);
|
||||||
if (NULL == buf) {
|
if (NULL == buf) {
|
||||||
@ -3734,14 +3748,14 @@ jint Arguments::parse_vm_options_file(const char* file_name, ScopedVMInitArgs* v
|
|||||||
return JNI_ENOMEM;
|
return JNI_ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(buf, 0, (unsigned)bytes_alloc);
|
memset(buf, 0, bytes_alloc);
|
||||||
|
|
||||||
// Fill buffer
|
// Fill buffer
|
||||||
// Use ::read() instead of os::read because os::read()
|
// Use ::read() instead of os::read because os::read()
|
||||||
// might do a thread state transition
|
// might do a thread state transition
|
||||||
// and it is too early for that here
|
// and it is too early for that here
|
||||||
|
|
||||||
int bytes_read = ::read(fd, (void *)buf, (unsigned)bytes_alloc);
|
ssize_t bytes_read = ::read(fd, (void *)buf, (unsigned)bytes_alloc);
|
||||||
os::close(fd);
|
os::close(fd);
|
||||||
if (bytes_read < 0) {
|
if (bytes_read < 0) {
|
||||||
FREE_C_HEAP_ARRAY(char, buf);
|
FREE_C_HEAP_ARRAY(char, buf);
|
||||||
@ -3756,16 +3770,7 @@ jint Arguments::parse_vm_options_file(const char* file_name, ScopedVMInitArgs* v
|
|||||||
return JNI_OK;
|
return JNI_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// file is larger than OPTION_BUFFER_SIZE
|
retcode = parse_options_buffer(file_name, buf, bytes_read, vm_args);
|
||||||
if (bytes_read > bytes_alloc - 1) {
|
|
||||||
FREE_C_HEAP_ARRAY(char, buf);
|
|
||||||
jio_fprintf(defaultStream::error_stream(),
|
|
||||||
"Options file '%s' is larger than %d bytes.\n",
|
|
||||||
file_name, bytes_alloc - 1);
|
|
||||||
return JNI_EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int retcode = parse_options_buffer(file_name, buf, bytes_read, vm_args);
|
|
||||||
|
|
||||||
FREE_C_HEAP_ARRAY(char, buf);
|
FREE_C_HEAP_ARRAY(char, buf);
|
||||||
return retcode;
|
return retcode;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user