summaryrefslogtreecommitdiffstats
path: root/recipes-core/openjdk/patches-openjdk-8/1004-hotspot-backport-patch-to-fix-misuses-of-strncpy-str.patch
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-core/openjdk/patches-openjdk-8/1004-hotspot-backport-patch-to-fix-misuses-of-strncpy-str.patch')
-rw-r--r--recipes-core/openjdk/patches-openjdk-8/1004-hotspot-backport-patch-to-fix-misuses-of-strncpy-str.patch172
1 files changed, 172 insertions, 0 deletions
diff --git a/recipes-core/openjdk/patches-openjdk-8/1004-hotspot-backport-patch-to-fix-misuses-of-strncpy-str.patch b/recipes-core/openjdk/patches-openjdk-8/1004-hotspot-backport-patch-to-fix-misuses-of-strncpy-str.patch
new file mode 100644
index 0000000..ad480e3
--- /dev/null
+++ b/recipes-core/openjdk/patches-openjdk-8/1004-hotspot-backport-patch-to-fix-misuses-of-strncpy-str.patch
@@ -0,0 +1,172 @@
1From 3a6eef99b27b7dd750e7a02eb3ada71db99d9345 Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?Andr=C3=A9=20Draszik?= <andre.draszik@jci.com>
3Date: Fri, 10 Aug 2018 14:54:45 +0100
4Subject: [PATCH 1004/1012] hotspot: backport patch to fix misuses of
5 strncpy/strncat
6MIME-Version: 1.0
7Content-Type: text/plain; charset=UTF-8
8Content-Transfer-Encoding: 8bit
9
10Various small fixes around strncpy and strncat
11
12Compilation using gcc >= 8 fails because of errors regarding
13misuse of string functions.
14Fix them using a backport from openjdk-10
15
16Modelled after http://hg.openjdk.java.net/jdk-updates/jdk10u/rev/b1608535e50f
17
18Signed-off-by: André Draszik <andre.draszik@jci.com>
19Signed-off-by: Richard Leitner <richard.leitner@skidata.com>
20---
21 agent/src/os/linux/libproc_impl.c | 7 ++++++-
22 src/share/tools/hsdis/hsdis.c | 1 +
23 src/share/vm/compiler/compileBroker.hpp | 3 ++-
24 src/share/vm/compiler/disassembler.cpp | 1 +
25 src/share/vm/runtime/arguments.cpp | 13 ++++++-------
26 src/share/vm/utilities/ostream.cpp | 12 ++++++++----
27 src/share/vm/utilities/vmError.cpp | 9 +--------
28 7 files changed, 25 insertions(+), 21 deletions(-)
29
30diff --git a/hotspot/agent/src/os/linux/libproc_impl.c b/hotspot/agent/src/os/linux/libproc_impl.c
31index ca791c95d..73a15ce35 100644
32--- a/hotspot/agent/src/os/linux/libproc_impl.c
33+++ b/hotspot/agent/src/os/linux/libproc_impl.c
34@@ -159,7 +159,12 @@ lib_info* add_lib_info_fd(struct ps_prochandle* ph, const char* libname, int fd,
35 return NULL;
36 }
37
38- strncpy(newlib->name, libname, sizeof(newlib->name));
39+ if (strlen(libname) >= sizeof(newlib->name)) {
40+ print_debug("libname %s too long\n", libname);
41+ return NULL;
42+ }
43+ strcpy(newlib->name, libname);
44+
45 newlib->base = base;
46
47 if (fd == -1) {
48diff --git a/hotspot/src/share/tools/hsdis/hsdis.c b/hotspot/src/share/tools/hsdis/hsdis.c
49index 7bef1040f..1907d479e 100644
50--- a/hotspot/src/share/tools/hsdis/hsdis.c
51+++ b/hotspot/src/share/tools/hsdis/hsdis.c
52@@ -438,6 +438,7 @@ static void parse_caller_options(struct hsdis_app_data* app_data, const char* ca
53 }
54 p = q;
55 }
56+ *iop = '\0';
57 }
58
59 static void print_help(struct hsdis_app_data* app_data,
60diff --git a/hotspot/src/share/vm/compiler/compileBroker.hpp b/hotspot/src/share/vm/compiler/compileBroker.hpp
61index ad37ff173..16e0ba3aa 100644
62--- a/hotspot/src/share/vm/compiler/compileBroker.hpp
63+++ b/hotspot/src/share/vm/compiler/compileBroker.hpp
64@@ -173,7 +173,8 @@ class CompilerCounters : public CHeapObj<mtCompiler> {
65 // these methods should be called in a thread safe context
66
67 void set_current_method(const char* method) {
68- strncpy(_current_method, method, (size_t)cmname_buffer_length);
69+ strncpy(_current_method, method, (size_t)cmname_buffer_length-1);
70+ _current_method[cmname_buffer_length-1] = '\0';
71 if (UsePerfData) _perf_current_method->set_value(method);
72 }
73
74diff --git a/hotspot/src/share/vm/compiler/disassembler.cpp b/hotspot/src/share/vm/compiler/disassembler.cpp
75index 93cd9e854..e7b32cd6b 100644
76--- a/hotspot/src/share/vm/compiler/disassembler.cpp
77+++ b/hotspot/src/share/vm/compiler/disassembler.cpp
78@@ -295,6 +295,7 @@ address decode_env::handle_event(const char* event, address arg) {
79 strlen((const char*)arg) > sizeof(buffer) - 1) {
80 // Only print this when the mach changes
81 strncpy(buffer, (const char*)arg, sizeof(buffer) - 1);
82+ buffer[sizeof(buffer) - 1] = '\0';
83 output()->print_cr("[Disassembling for mach='%s']", arg);
84 }
85 } else if (match(event, "format bytes-per-line")) {
86diff --git a/hotspot/src/share/vm/runtime/arguments.cpp b/hotspot/src/share/vm/runtime/arguments.cpp
87index 2665b6b8c..5a9294677 100644
88--- a/hotspot/src/share/vm/runtime/arguments.cpp
89+++ b/hotspot/src/share/vm/runtime/arguments.cpp
90@@ -3455,7 +3455,7 @@ void Arguments::fix_appclasspath() {
91 }
92
93 char* copy = AllocateHeap(strlen(src) + 1, mtInternal);
94- strncpy(copy, src, strlen(src) + 1);
95+ strcpy(copy, src);
96
97 // trim all trailing empty paths
98 for (char* tail = copy + strlen(copy) - 1; tail >= copy && *tail == separator; tail--) {
99@@ -3834,17 +3834,16 @@ static char* get_shared_archive_path() {
100 if (end != NULL) *end = '\0';
101 size_t jvm_path_len = strlen(jvm_path);
102 size_t file_sep_len = strlen(os::file_separator());
103- shared_archive_path = NEW_C_HEAP_ARRAY(char, jvm_path_len +
104- file_sep_len + 20, mtInternal);
105+ const size_t len = jvm_path_len + file_sep_len + 20;
106+ shared_archive_path = NEW_C_HEAP_ARRAY(char, len, mtInternal);
107 if (shared_archive_path != NULL) {
108- strncpy(shared_archive_path, jvm_path, jvm_path_len + 1);
109- strncat(shared_archive_path, os::file_separator(), file_sep_len);
110- strncat(shared_archive_path, "classes.jsa", 11);
111+ jio_snprintf(shared_archive_path, len, "%s%sclasses.jsa",
112+ jvm_path, os::file_separator());
113 }
114 } else {
115 shared_archive_path = NEW_C_HEAP_ARRAY(char, strlen(SharedArchiveFile) + 1, mtInternal);
116 if (shared_archive_path != NULL) {
117- strncpy(shared_archive_path, SharedArchiveFile, strlen(SharedArchiveFile) + 1);
118+ strcpy(shared_archive_path, SharedArchiveFile);
119 }
120 }
121 return shared_archive_path;
122diff --git a/hotspot/src/share/vm/utilities/ostream.cpp b/hotspot/src/share/vm/utilities/ostream.cpp
123index 1b00f829a..4daea2b7e 100644
124--- a/hotspot/src/share/vm/utilities/ostream.cpp
125+++ b/hotspot/src/share/vm/utilities/ostream.cpp
126@@ -342,15 +342,19 @@ void stringStream::write(const char* s, size_t len) {
127 assert(rm == NULL || Thread::current()->current_resource_mark() == rm,
128 "stringStream is re-allocated with a different ResourceMark");
129 buffer = NEW_RESOURCE_ARRAY(char, end);
130- strncpy(buffer, oldbuf, buffer_pos);
131+ if (buffer_pos > 0) {
132+ memcpy(buffer, oldbuf, buffer_pos);
133+ }
134 buffer_length = end;
135 }
136 }
137 // invariant: buffer is always null-terminated
138 guarantee(buffer_pos + write_len + 1 <= buffer_length, "stringStream oob");
139- buffer[buffer_pos + write_len] = 0;
140- strncpy(buffer + buffer_pos, s, write_len);
141- buffer_pos += write_len;
142+ if (write_len > 0) {
143+ buffer[buffer_pos + write_len] = 0;
144+ memcpy(buffer + buffer_pos, s, write_len);
145+ buffer_pos += write_len;
146+ }
147
148 // Note that the following does not depend on write_len.
149 // This means that position and count get updated
150diff --git a/hotspot/src/share/vm/utilities/vmError.cpp b/hotspot/src/share/vm/utilities/vmError.cpp
151index ef3bb5cee..c11fef472 100644
152--- a/hotspot/src/share/vm/utilities/vmError.cpp
153+++ b/hotspot/src/share/vm/utilities/vmError.cpp
154@@ -450,14 +450,7 @@ void VMError::report(outputStream* st) {
155 #else
156 const char *file = _filename;
157 #endif
158- size_t len = strlen(file);
159- size_t buflen = sizeof(buf);
160-
161- strncpy(buf, file, buflen);
162- if (len + 10 < buflen) {
163- sprintf(buf + len, ":%d", _lineno);
164- }
165- st->print(" (%s)", buf);
166+ st->print(" (%s:%d)", file, _lineno);
167 } else {
168 st->print(" (0x%x)", _id);
169 }
170--
1712.24.1
172