mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8214777: Avoid some GCC 8.X strncpy() errors in HotSpot
Reviewed-by: kbarrett, rehn
This commit is contained in:
parent
46666a2d94
commit
15d554b395
12 changed files with 59 additions and 73 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -859,11 +859,7 @@ char* SystemProcessInterface::SystemProcesses::ProcessIterator::get_exe_path() {
|
||||||
|
|
||||||
char* SystemProcessInterface::SystemProcesses::ProcessIterator::allocate_string(const char* str) const {
|
char* SystemProcessInterface::SystemProcesses::ProcessIterator::allocate_string(const char* str) const {
|
||||||
if (str != NULL) {
|
if (str != NULL) {
|
||||||
size_t len = strlen(str);
|
return os::strdup_check_oom(str, mtInternal);
|
||||||
char* tmp = NEW_C_HEAP_ARRAY(char, len+1, mtInternal);
|
|
||||||
strncpy(tmp, str, len);
|
|
||||||
tmp[len] = '\0';
|
|
||||||
return tmp;
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -861,11 +861,7 @@ char* SystemProcessInterface::SystemProcesses::ProcessIterator::get_exe_path() {
|
||||||
|
|
||||||
char* SystemProcessInterface::SystemProcesses::ProcessIterator::allocate_string(const char* str) const {
|
char* SystemProcessInterface::SystemProcesses::ProcessIterator::allocate_string(const char* str) const {
|
||||||
if (str != NULL) {
|
if (str != NULL) {
|
||||||
size_t len = strlen(str);
|
return os::strdup_check_oom(str, mtInternal);
|
||||||
char* tmp = NEW_C_HEAP_ARRAY(char, len+1, mtInternal);
|
|
||||||
strncpy(tmp, str, len);
|
|
||||||
tmp[len] = '\0';
|
|
||||||
return tmp;
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,13 +180,14 @@ int os::create_file_for_heap(const char* dir) {
|
||||||
|
|
||||||
const char name_template[] = "/jvmheap.XXXXXX";
|
const char name_template[] = "/jvmheap.XXXXXX";
|
||||||
|
|
||||||
char *fullname = (char*)os::malloc((strlen(dir) + strlen(name_template) + 1), mtInternal);
|
size_t fullname_len = strlen(dir) + strlen(name_template);
|
||||||
|
char *fullname = (char*)os::malloc(fullname_len + 1, mtInternal);
|
||||||
if (fullname == NULL) {
|
if (fullname == NULL) {
|
||||||
vm_exit_during_initialization(err_msg("Malloc failed during creation of backing file for heap (%s)", os::strerror(errno)));
|
vm_exit_during_initialization(err_msg("Malloc failed during creation of backing file for heap (%s)", os::strerror(errno)));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
(void)strncpy(fullname, dir, strlen(dir)+1);
|
int n = snprintf(fullname, fullname_len + 1, "%s%s", dir, name_template);
|
||||||
(void)strncat(fullname, name_template, strlen(name_template));
|
assert((size_t)n == fullname_len, "Unexpected number of characters in string");
|
||||||
|
|
||||||
os::native_path(fullname);
|
os::native_path(fullname);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -544,11 +544,7 @@ bool SystemProcessInterface::SystemProcesses::ProcessIterator::is_valid_entry(st
|
||||||
|
|
||||||
char* SystemProcessInterface::SystemProcesses::ProcessIterator::allocate_string(const char* str) const {
|
char* SystemProcessInterface::SystemProcesses::ProcessIterator::allocate_string(const char* str) const {
|
||||||
if (str != NULL) {
|
if (str != NULL) {
|
||||||
size_t len = strlen(str);
|
return os::strdup_check_oom(str, mtInternal);
|
||||||
char* tmp = NEW_C_HEAP_ARRAY(char, len+1, mtInternal);
|
|
||||||
strncpy(tmp, str, len);
|
|
||||||
tmp[len] = '\0';
|
|
||||||
return tmp;
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -1253,14 +1253,7 @@ int SystemProcessInterface::SystemProcesses::ProcessIterator::current(SystemProc
|
||||||
|
|
||||||
char* SystemProcessInterface::SystemProcesses::ProcessIterator::allocate_string(const char* str) const {
|
char* SystemProcessInterface::SystemProcesses::ProcessIterator::allocate_string(const char* str) const {
|
||||||
if (str != NULL) {
|
if (str != NULL) {
|
||||||
size_t len = strlen(str);
|
return os::strdup_check_oom(str, mtInternal);
|
||||||
char* tmp = NEW_C_HEAP_ARRAY(char, len+1, mtInternal);
|
|
||||||
if (NULL == tmp) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
strncpy(tmp, str, len);
|
|
||||||
tmp[len] = '\0';
|
|
||||||
return tmp;
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2970,14 +2970,15 @@ void os::large_page_init() {
|
||||||
int os::create_file_for_heap(const char* dir) {
|
int os::create_file_for_heap(const char* dir) {
|
||||||
|
|
||||||
const char name_template[] = "/jvmheap.XXXXXX";
|
const char name_template[] = "/jvmheap.XXXXXX";
|
||||||
char *fullname = (char*)os::malloc((strlen(dir) + strlen(name_template) + 1), mtInternal);
|
|
||||||
|
size_t fullname_len = strlen(dir) + strlen(name_template);
|
||||||
|
char *fullname = (char*)os::malloc(fullname_len + 1, mtInternal);
|
||||||
if (fullname == NULL) {
|
if (fullname == NULL) {
|
||||||
vm_exit_during_initialization(err_msg("Malloc failed during creation of backing file for heap (%s)", os::strerror(errno)));
|
vm_exit_during_initialization(err_msg("Malloc failed during creation of backing file for heap (%s)", os::strerror(errno)));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
int n = snprintf(fullname, fullname_len + 1, "%s%s", dir, name_template);
|
||||||
(void)strncpy(fullname, dir, strlen(dir)+1);
|
assert((size_t)n == fullname_len, "Unexpected number of characters in string");
|
||||||
(void)strncat(fullname, name_template, strlen(name_template));
|
|
||||||
|
|
||||||
os::native_path(fullname);
|
os::native_path(fullname);
|
||||||
|
|
||||||
|
|
|
@ -5743,16 +5743,13 @@ void ClassFileParser::prepend_host_package_name(const InstanceKlass* unsafe_anon
|
||||||
ClassLoader::package_from_name(unsafe_anonymous_host->name()->as_C_string(), NULL);
|
ClassLoader::package_from_name(unsafe_anonymous_host->name()->as_C_string(), NULL);
|
||||||
|
|
||||||
if (host_pkg_name != NULL) {
|
if (host_pkg_name != NULL) {
|
||||||
size_t host_pkg_len = strlen(host_pkg_name);
|
int host_pkg_len = (int)strlen(host_pkg_name);
|
||||||
int class_name_len = _class_name->utf8_length();
|
int class_name_len = _class_name->utf8_length();
|
||||||
char* new_anon_name =
|
int symbol_len = host_pkg_len + 1 + class_name_len;
|
||||||
NEW_RESOURCE_ARRAY(char, host_pkg_len + 1 + class_name_len);
|
char* new_anon_name = NEW_RESOURCE_ARRAY(char, symbol_len + 1);
|
||||||
// Copy host package name and trailing /.
|
int n = snprintf(new_anon_name, symbol_len + 1, "%s/%.*s",
|
||||||
strncpy(new_anon_name, host_pkg_name, host_pkg_len);
|
host_pkg_name, class_name_len, _class_name->base());
|
||||||
new_anon_name[host_pkg_len] = '/';
|
assert(n == symbol_len, "Unexpected number of characters in string");
|
||||||
// Append unsafe anonymous class name. The unsafe anonymous class name can contain odd
|
|
||||||
// characters. So, do a strncpy instead of using sprintf("%s...").
|
|
||||||
strncpy(new_anon_name + host_pkg_len + 1, (char *)_class_name->base(), class_name_len);
|
|
||||||
|
|
||||||
// Decrement old _class_name to avoid leaking.
|
// Decrement old _class_name to avoid leaking.
|
||||||
_class_name->decrement_refcount();
|
_class_name->decrement_refcount();
|
||||||
|
@ -5761,9 +5758,7 @@ void ClassFileParser::prepend_host_package_name(const InstanceKlass* unsafe_anon
|
||||||
// The new class name is created with a refcount of one. When installed into the InstanceKlass,
|
// The new class name is created with a refcount of one. When installed into the InstanceKlass,
|
||||||
// it'll be two and when the ClassFileParser destructor runs, it'll go back to one and get deleted
|
// it'll be two and when the ClassFileParser destructor runs, it'll go back to one and get deleted
|
||||||
// when the class is unloaded.
|
// when the class is unloaded.
|
||||||
_class_name = SymbolTable::new_symbol(new_anon_name,
|
_class_name = SymbolTable::new_symbol(new_anon_name, symbol_len, CHECK);
|
||||||
(int)host_pkg_len + 1 + class_name_len,
|
|
||||||
CHECK);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -203,13 +203,13 @@ void ClassLoaderExt::process_jar_manifest(ClassPathEntry* entry,
|
||||||
file_end = end;
|
file_end = end;
|
||||||
}
|
}
|
||||||
|
|
||||||
int name_len = (int)strlen(file_start);
|
size_t name_len = strlen(file_start);
|
||||||
if (name_len > 0) {
|
if (name_len > 0) {
|
||||||
ResourceMark rm(THREAD);
|
ResourceMark rm(THREAD);
|
||||||
char* libname = NEW_RESOURCE_ARRAY(char, dir_len + name_len + 1);
|
size_t libname_len = dir_len + name_len;
|
||||||
*libname = 0;
|
char* libname = NEW_RESOURCE_ARRAY(char, libname_len + 1);
|
||||||
strncat(libname, dir_name, dir_len);
|
int n = snprintf(libname, libname_len + 1, "%.*s%s", dir_len, dir_name, file_start);
|
||||||
strncat(libname, file_start, name_len);
|
assert((size_t)n == libname_len, "Unexpected number of characters in string");
|
||||||
trace_class_path("library = ", libname);
|
trace_class_path("library = ", libname);
|
||||||
ClassLoader::update_class_path_entry_list(libname, true, false);
|
ClassLoader::update_class_path_entry_list(libname, true, false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -2981,18 +2981,16 @@ void ClassVerifier::verify_anewarray(
|
||||||
}
|
}
|
||||||
// add one dimension to component
|
// add one dimension to component
|
||||||
length++;
|
length++;
|
||||||
arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length);
|
arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length + 1);
|
||||||
arr_sig_str[0] = '[';
|
int n = snprintf(arr_sig_str, length + 1, "[%s", component_name);
|
||||||
strncpy(&arr_sig_str[1], component_name, length - 1);
|
assert(n == length, "Unexpected number of characters in string");
|
||||||
} else { // it's an object or interface
|
} else { // it's an object or interface
|
||||||
const char* component_name = component_type.name()->as_utf8();
|
const char* component_name = component_type.name()->as_utf8();
|
||||||
// add one dimension to component with 'L' prepended and ';' postpended.
|
// add one dimension to component with 'L' prepended and ';' postpended.
|
||||||
length = (int)strlen(component_name) + 3;
|
length = (int)strlen(component_name) + 3;
|
||||||
arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length);
|
arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length + 1);
|
||||||
arr_sig_str[0] = '[';
|
int n = snprintf(arr_sig_str, length + 1, "[L%s;", component_name);
|
||||||
arr_sig_str[1] = 'L';
|
assert(n == length, "Unexpected number of characters in string");
|
||||||
strncpy(&arr_sig_str[2], component_name, length - 2);
|
|
||||||
arr_sig_str[length - 1] = ';';
|
|
||||||
}
|
}
|
||||||
Symbol* arr_sig = create_temporary_symbol(
|
Symbol* arr_sig = create_temporary_symbol(
|
||||||
arr_sig_str, length, CHECK_VERIFY(this));
|
arr_sig_str, length, CHECK_VERIFY(this));
|
||||||
|
|
|
@ -2454,9 +2454,15 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_m
|
||||||
(is_absolute_path = match_option(option, "-agentpath:", &tail))) {
|
(is_absolute_path = match_option(option, "-agentpath:", &tail))) {
|
||||||
if(tail != NULL) {
|
if(tail != NULL) {
|
||||||
const char* pos = strchr(tail, '=');
|
const char* pos = strchr(tail, '=');
|
||||||
size_t len = (pos == NULL) ? strlen(tail) : pos - tail;
|
char* name;
|
||||||
char* name = strncpy(NEW_C_HEAP_ARRAY(char, len + 1, mtArguments), tail, len);
|
if (pos == NULL) {
|
||||||
name[len] = '\0';
|
name = os::strdup_check_oom(tail, mtArguments);
|
||||||
|
} else {
|
||||||
|
size_t len = pos - tail;
|
||||||
|
name = NEW_C_HEAP_ARRAY(char, len + 1, mtArguments);
|
||||||
|
memcpy(name, tail, len);
|
||||||
|
name[len] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
char *options = NULL;
|
char *options = NULL;
|
||||||
if(pos != NULL) {
|
if(pos != NULL) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -179,9 +179,9 @@ template <> void DCmdArgument<char*>::parse_value(const char* str,
|
||||||
if (str == NULL) {
|
if (str == NULL) {
|
||||||
_value = NULL;
|
_value = NULL;
|
||||||
} else {
|
} else {
|
||||||
_value = NEW_C_HEAP_ARRAY(char, len+1, mtInternal);
|
_value = NEW_C_HEAP_ARRAY(char, len + 1, mtInternal);
|
||||||
strncpy(_value, str, len);
|
int n = snprintf(_value, len + 1, "%.*s", (int)len, str);
|
||||||
_value[len] = 0;
|
assert((size_t)n <= len, "Unexpected number of characters in string");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -353,11 +353,15 @@ void xmlStream::va_done(const char* format, va_list ap) {
|
||||||
guarantee(format_len + 10 < sizeof(buffer), "bigger format buffer");
|
guarantee(format_len + 10 < sizeof(buffer), "bigger format buffer");
|
||||||
const char* kind = format;
|
const char* kind = format;
|
||||||
const char* kind_end = strchr(kind, ' ');
|
const char* kind_end = strchr(kind, ' ');
|
||||||
size_t kind_len = (kind_end != NULL) ? (kind_end - kind) : format_len;
|
size_t kind_len;
|
||||||
strncpy(buffer, kind, kind_len);
|
|
||||||
strcpy(buffer + kind_len, "_done");
|
|
||||||
if (kind_end != NULL) {
|
if (kind_end != NULL) {
|
||||||
strncat(buffer, format + kind_len, sizeof(buffer) - (kind_len + 5 /* _done */) - 1);
|
kind_len = kind_end - kind;
|
||||||
|
int n = snprintf(buffer, sizeof(buffer), "%.*s_done", (int)kind_len, kind);
|
||||||
|
assert((size_t)n < sizeof(buffer), "Unexpected number of characters in string");
|
||||||
|
} else {
|
||||||
|
kind_len = format_len;
|
||||||
|
int n = snprintf(buffer, sizeof(buffer), "%s_done%s", kind, kind + kind_len);
|
||||||
|
assert((size_t)n < sizeof(buffer), "Unexpected number of characters in string");
|
||||||
}
|
}
|
||||||
// Output the trailing event with the timestamp.
|
// Output the trailing event with the timestamp.
|
||||||
va_begin_elem(buffer, ap);
|
va_begin_elem(buffer, ap);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue