8223813: (aio) Iocp.getErrorMessage should drop trailing \r\n
Reviewed-by: alanb, igerasim, rriggs
This commit is contained in:
parent
aeedfd44b0
commit
179d586e72
src/java.base/windows/native
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -359,7 +359,8 @@ ping4(JNIEnv *env, HANDLE hIcmpFile, SOCKETADDRESS *sa,
|
||||
}
|
||||
|
||||
if (dwRetVal == 0) { // if the call failed
|
||||
TCHAR *buf;
|
||||
TCHAR *buf = NULL;
|
||||
DWORD n;
|
||||
DWORD err = WSAGetLastError();
|
||||
switch (err) {
|
||||
case ERROR_NO_NETWORK:
|
||||
@ -379,9 +380,17 @@ ping4(JNIEnv *env, HANDLE hIcmpFile, SOCKETADDRESS *sa,
|
||||
case IP_REQ_TIMED_OUT:
|
||||
break;
|
||||
default:
|
||||
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
||||
NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(LPTSTR)&buf, 0, NULL);
|
||||
n = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM,
|
||||
NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(LPTSTR)&buf, 0, NULL);
|
||||
if (n > 3) {
|
||||
// Drop final '.', CR, LF
|
||||
if (buf[n - 1] == TEXT('\n')) n--;
|
||||
if (buf[n - 1] == TEXT('\r')) n--;
|
||||
if (buf[n - 1] == TEXT('.')) n--;
|
||||
buf[n] = TEXT('\0');
|
||||
}
|
||||
NET_ThrowNew(env, err, buf);
|
||||
LocalFree(buf);
|
||||
break;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -142,6 +142,14 @@ Java_sun_nio_ch_Iocp_getErrorMessage(JNIEnv* env, jclass this, jint errorCode)
|
||||
if (len == 0) {
|
||||
return NULL;
|
||||
} else {
|
||||
if (len > 3) {
|
||||
// Drop final '.', CR, LF
|
||||
if (message[len - 1] == L'\n') len--;
|
||||
if (message[len - 1] == L'\r') len--;
|
||||
if (message[len - 1] == L'.') len--;
|
||||
message[len] = L'\0';
|
||||
}
|
||||
|
||||
return (*env)->NewString(env, (const jchar *)message, (jsize)wcslen(message));
|
||||
}
|
||||
}
|
||||
|
@ -177,6 +177,14 @@ Java_sun_nio_fs_WindowsNativeDispatcher_FormatMessage(JNIEnv* env, jclass this,
|
||||
if (len == 0) {
|
||||
return NULL;
|
||||
} else {
|
||||
if (len > 3) {
|
||||
// Drop final '.', CR, LF
|
||||
if (message[len - 1] == L'\n') len--;
|
||||
if (message[len - 1] == L'\r') len--;
|
||||
if (message[len - 1] == L'.') len--;
|
||||
message[len] = L'\0';
|
||||
}
|
||||
|
||||
return (*env)->NewString(env, (const jchar *)message, (jsize)wcslen(message));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user