changeset 55888:d57d61aafef9

8223813: (aio) Iocp.getErrorMessage should drop trailing \r\n Reviewed-by: alanb, igerasim, rriggs
author bpb
date Thu, 13 Jun 2019 13:43:34 -0700
parents 761b86d5563d
children 5c52d053cb14
files src/java.base/windows/native/libnet/Inet4AddressImpl.c src/java.base/windows/native/libnio/ch/Iocp.c src/java.base/windows/native/libnio/fs/WindowsNativeDispatcher.c
diffstat 3 files changed, 31 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/windows/native/libnet/Inet4AddressImpl.c	Thu Jun 13 11:50:45 2019 -0700
+++ b/src/java.base/windows/native/libnet/Inet4AddressImpl.c	Thu Jun 13 13:43:34 2019 -0700
@@ -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 @@
     }
 
     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 @@
             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;
--- a/src/java.base/windows/native/libnio/ch/Iocp.c	Thu Jun 13 11:50:45 2019 -0700
+++ b/src/java.base/windows/native/libnio/ch/Iocp.c	Thu Jun 13 13:43:34 2019 -0700
@@ -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 @@
     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));
     }
 }
--- a/src/java.base/windows/native/libnio/fs/WindowsNativeDispatcher.c	Thu Jun 13 11:50:45 2019 -0700
+++ b/src/java.base/windows/native/libnio/fs/WindowsNativeDispatcher.c	Thu Jun 13 13:43:34 2019 -0700
@@ -177,6 +177,14 @@
     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));
     }
 }