8242283: Can't start JVM when java home path includes non-ASCII character

Reviewed-by: naoto, hseigel
This commit is contained in:
Yasumasa Suenaga 2020-04-14 09:03:38 +09:00
parent 4a09f31eff
commit d34f732b99
5 changed files with 11 additions and 11 deletions

View file

@ -4143,7 +4143,7 @@ static void file_attribute_data_to_stat(struct stat* sbuf, WIN32_FILE_ATTRIBUTE_
static errno_t convert_to_unicode(char const* char_path, LPWSTR* unicode_path) { static errno_t convert_to_unicode(char const* char_path, LPWSTR* unicode_path) {
// Get required buffer size to convert to Unicode // Get required buffer size to convert to Unicode
int unicode_path_len = MultiByteToWideChar(CP_THREAD_ACP, int unicode_path_len = MultiByteToWideChar(CP_ACP,
MB_ERR_INVALID_CHARS, MB_ERR_INVALID_CHARS,
char_path, -1, char_path, -1,
NULL, 0); NULL, 0);
@ -4153,7 +4153,7 @@ static errno_t convert_to_unicode(char const* char_path, LPWSTR* unicode_path) {
*unicode_path = NEW_C_HEAP_ARRAY(WCHAR, unicode_path_len, mtInternal); *unicode_path = NEW_C_HEAP_ARRAY(WCHAR, unicode_path_len, mtInternal);
int result = MultiByteToWideChar(CP_THREAD_ACP, int result = MultiByteToWideChar(CP_ACP,
MB_ERR_INVALID_CHARS, MB_ERR_INVALID_CHARS,
char_path, -1, char_path, -1,
*unicode_path, unicode_path_len); *unicode_path, unicode_path_len);

View file

@ -136,7 +136,7 @@ ZFILE_Open(const char *fname, int flags) {
NULL); NULL);
} else { } else {
/* Get required buffer size to convert to Unicode */ /* Get required buffer size to convert to Unicode */
int wfname_len = MultiByteToWideChar(CP_THREAD_ACP, MB_ERR_INVALID_CHARS, int wfname_len = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS,
fname, -1, NULL, 0); fname, -1, NULL, 0);
if (wfname_len == 0) { if (wfname_len == 0) {
return (jlong)INVALID_HANDLE_VALUE; return (jlong)INVALID_HANDLE_VALUE;
@ -144,7 +144,7 @@ ZFILE_Open(const char *fname, int flags) {
if ((wfname = (WCHAR*)malloc(wfname_len * sizeof(WCHAR))) == NULL) { if ((wfname = (WCHAR*)malloc(wfname_len * sizeof(WCHAR))) == NULL) {
return (jlong)INVALID_HANDLE_VALUE; return (jlong)INVALID_HANDLE_VALUE;
} }
if (MultiByteToWideChar(CP_THREAD_ACP, MB_ERR_INVALID_CHARS, if (MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS,
fname, -1, wfname, wfname_len) == 0) { fname, -1, wfname, wfname_len) == 0) {
free(wfname); free(wfname);
return (jlong)INVALID_HANDLE_VALUE; return (jlong)INVALID_HANDLE_VALUE;

View file

@ -334,7 +334,7 @@ JDK_Canonicalize(const char *orig, char *out, int len) {
int ret = -1; int ret = -1;
/* Get required buffer size to convert to Unicode */ /* Get required buffer size to convert to Unicode */
wpath_len = MultiByteToWideChar(CP_THREAD_ACP, MB_ERR_INVALID_CHARS, wpath_len = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS,
orig, -1, NULL, 0); orig, -1, NULL, 0);
if (wpath_len == 0) { if (wpath_len == 0) {
goto finish; goto finish;
@ -344,7 +344,7 @@ JDK_Canonicalize(const char *orig, char *out, int len) {
goto finish; goto finish;
} }
if (MultiByteToWideChar(CP_THREAD_ACP, MB_ERR_INVALID_CHARS, if (MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS,
orig, -1, wpath, wpath_len) == 0) { orig, -1, wpath, wpath_len) == 0) {
goto finish; goto finish;
} }
@ -357,7 +357,7 @@ JDK_Canonicalize(const char *orig, char *out, int len) {
goto finish; goto finish;
} }
if (WideCharToMultiByte(CP_THREAD_ACP, 0, if (WideCharToMultiByte(CP_ACP, 0,
wresult, -1, out, len, NULL, NULL) == 0) { wresult, -1, out, len, NULL, NULL) == 0) {
goto finish; goto finish;
} }

View file

@ -504,7 +504,7 @@ static errno_t convert_to_unicode(const char* path, const wchar_t* prefix, wchar
* Get required buffer size to convert to Unicode. * Get required buffer size to convert to Unicode.
* The return value includes the terminating null character. * The return value includes the terminating null character.
*/ */
unicode_path_len = MultiByteToWideChar(CP_THREAD_ACP, MB_ERR_INVALID_CHARS, unicode_path_len = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS,
path, -1, NULL, 0); path, -1, NULL, 0);
if (unicode_path_len == 0) { if (unicode_path_len == 0) {
return EINVAL; return EINVAL;
@ -518,7 +518,7 @@ static errno_t convert_to_unicode(const char* path, const wchar_t* prefix, wchar
} }
wcsncpy(*wpath, prefix, prefix_len); wcsncpy(*wpath, prefix, prefix_len);
if (MultiByteToWideChar(CP_THREAD_ACP, MB_ERR_INVALID_CHARS, if (MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS,
path, -1, &((*wpath)[prefix_len]), (int)wpath_len) == 0) { path, -1, &((*wpath)[prefix_len]), (int)wpath_len) == 0) {
JLI_MemFree(*wpath); JLI_MemFree(*wpath);
*wpath = NULL; *wpath = NULL;

View file

@ -404,12 +404,12 @@ WideString Platform::MultibyteStringToWideString(const char* value) {
return result; return result;
} }
count = MultiByteToWideChar(CP_THREAD_ACP, MB_ERR_INVALID_CHARS, count = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS,
value, -1, NULL, 0); value, -1, NULL, 0);
if (count > 0) { if (count > 0) {
result.data = new wchar_t[count]; result.data = new wchar_t[count];
result.length = MultiByteToWideChar(CP_THREAD_ACP, MB_ERR_INVALID_CHARS, result.length = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS,
value, -1, result.data, (int)count); value, -1, result.data, (int)count);
if (result.length == 0) { if (result.length == 0) {
delete[] result.data; delete[] result.data;