8133034: launcher crashes if started with non english arguments
Submitten-by: almatvee
Reviewed-by: herrick
--- a/src/jdk.packager/share/native/library/common/PlatformString.cpp Fri Oct 05 14:47:35 2018 -0400
+++ b/src/jdk.packager/share/native/library/common/PlatformString.cpp Mon Oct 08 18:10:31 2018 -0400
@@ -133,14 +133,18 @@
MultibyteString result;
size_t count = 0;
+ if (value == NULL) {
+ return result;
+ }
+
#ifdef WINDOWS
- wcstombs_s(&count, NULL, 0, value, 0);
+ count = WideCharToMultiByte(CP_UTF8, 0, value, -1, NULL, 0, NULL, NULL);
if (count > 0) {
result.data = new char[count + 1];
- wcstombs_s(&result.length, result.data, count, value, count);
+ result.length = WideCharToMultiByte(CP_UTF8, 0, value, -1, result.data, (int)count, NULL, NULL);
+#endif //WINDOWS
-#endif //WINDOWS
#ifdef POSIX
count = wcstombs(NULL, value, 0);
@@ -160,6 +164,10 @@
WideString result;
size_t count = 0;
+ if (value == NULL) {
+ return result;
+ }
+
#ifdef WINDOWS
mbstowcs_s(&count, NULL, 0, value, _TRUNCATE);