Merge
authordcubed
Fri, 15 Jul 2016 18:09:33 +0000
changeset 40183 c07bb9175087
parent 40181 a8c9eb3e97e2 (current diff)
parent 40182 1e16a8fd76ba (diff)
child 40184 aed163cc3cc2
Merge
--- a/jdk/src/java.base/unix/native/libjava/ProcessHandleImpl_unix.c	Fri Jul 15 09:10:36 2016 -0700
+++ b/jdk/src/java.base/unix/native/libjava/ProcessHandleImpl_unix.c	Fri Jul 15 18:09:33 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, 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
@@ -34,7 +34,6 @@
 #include <stdio.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <pwd.h>
 #include <signal.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -46,6 +45,12 @@
 #include <sys/stat.h>
 #include <sys/wait.h>
 
+/* For POSIX-compliant getpwuid_r on Solaris */
+#if defined(__solaris__)
+#define _POSIX_PTHREAD_SEMANTICS
+#endif
+#include <pwd.h>
+
 #ifdef _AIX
 #include <sys/procfs.h>
 #endif
@@ -468,12 +473,7 @@
     } else {
         struct passwd pwent;
         struct passwd* p = NULL;
-
-#ifdef __solaris__
-        RESTARTABLE_RETURN_PTR(getpwuid_r(uid, &pwent, pwbuf, (size_t)getpw_buf_size), p);
-#else
         RESTARTABLE(getpwuid_r(uid, &pwent, pwbuf, (size_t)getpw_buf_size, &p), result);
-#endif
 
         // Create the Java String if a name was found
         if (result == 0 && p != NULL &&
--- a/jdk/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c	Fri Jul 15 09:10:36 2016 -0700
+++ b/jdk/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c	Fri Jul 15 18:09:33 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2016, 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
@@ -29,8 +29,6 @@
 #include <fcntl.h>
 #include <dirent.h>
 #include <unistd.h>
-#include <pwd.h>
-#include <grp.h>
 #include <errno.h>
 #include <dlfcn.h>
 #include <sys/types.h>
@@ -43,6 +41,13 @@
 #endif
 #include <sys/time.h>
 
+/* For POSIX-compliant getpwuid_r, getgrgid_r on Solaris */
+#if defined(__solaris__)
+#define _POSIX_PTHREAD_SEMANTICS
+#endif
+#include <pwd.h>
+#include <grp.h>
+
 #ifdef __solaris__
 #include <strings.h>
 #endif
@@ -1022,11 +1027,7 @@
         int res = 0;
 
         errno = 0;
-        #ifdef __solaris__
-            RESTARTABLE_RETURN_PTR(getpwuid_r((uid_t)uid, &pwent, pwbuf, (size_t)buflen), p);
-        #else
-            RESTARTABLE(getpwuid_r((uid_t)uid, &pwent, pwbuf, (size_t)buflen, &p), res);
-        #endif
+        RESTARTABLE(getpwuid_r((uid_t)uid, &pwent, pwbuf, (size_t)buflen, &p), res);
 
         if (res != 0 || p == NULL || p->pw_name == NULL || *(p->pw_name) == '\0') {
             /* not found or error */
@@ -1071,11 +1072,7 @@
         }
 
         errno = 0;
-        #ifdef __solaris__
-            RESTARTABLE_RETURN_PTR(getgrgid_r((gid_t)gid, &grent, grbuf, (size_t)buflen), g);
-        #else
-            RESTARTABLE(getgrgid_r((gid_t)gid, &grent, grbuf, (size_t)buflen, &g), res);
-        #endif
+        RESTARTABLE(getgrgid_r((gid_t)gid, &grent, grbuf, (size_t)buflen, &g), res);
 
         retry = 0;
         if (res != 0 || g == NULL || g->gr_name == NULL || *(g->gr_name) == '\0') {
@@ -1126,11 +1123,7 @@
         const char* name = (const char*)jlong_to_ptr(nameAddress);
 
         errno = 0;
-        #ifdef __solaris__
-            RESTARTABLE_RETURN_PTR(getpwnam_r(name, &pwent, pwbuf, (size_t)buflen), p);
-        #else
-            RESTARTABLE(getpwnam_r(name, &pwent, pwbuf, (size_t)buflen, &p), res);
-        #endif
+        RESTARTABLE(getpwnam_r(name, &pwent, pwbuf, (size_t)buflen, &p), res);
 
         if (res != 0 || p == NULL || p->pw_name == NULL || *(p->pw_name) == '\0') {
             /* not found or error */
@@ -1171,11 +1164,7 @@
         }
 
         errno = 0;
-        #ifdef __solaris__
-            RESTARTABLE_RETURN_PTR(getgrnam_r(name, &grent, grbuf, (size_t)buflen), g);
-        #else
-            RESTARTABLE(getgrnam_r(name, &grent, grbuf, (size_t)buflen, &g), res);
-        #endif
+        RESTARTABLE(getgrnam_r(name, &grent, grbuf, (size_t)buflen, &g), res);
 
         retry = 0;
         if (res != 0 || g == NULL || g->gr_name == NULL || *(g->gr_name) == '\0') {
--- a/jdk/src/jdk.security.auth/solaris/native/libjaas/Solaris.c	Fri Jul 15 09:10:36 2016 -0700
+++ b/jdk/src/jdk.security.auth/solaris/native/libjaas/Solaris.c	Fri Jul 15 18:09:33 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2016, 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
@@ -26,10 +26,14 @@
 #include <jni.h>
 #include "com_sun_security_auth_module_SolarisSystem.h"
 #include <stdio.h>
-#include <pwd.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
+
+/* For POSIX-compliant getpwuid_r on Solaris */
+#if defined(__solaris__)
+#define _POSIX_PTHREAD_SEMANTICS
+#endif
 #include <pwd.h>
 
 static void throwIllegalArgumentException(JNIEnv *env, const char *msg) {
@@ -43,8 +47,10 @@
                                                 (JNIEnv *env, jobject obj) {
 
     int i;
-    char pwd_buf[1024];
+    long pwd_bufsize;
+    char *pwd_buf = NULL;
     struct passwd pwd;
+    struct passwd* p = NULL;
     jsize numSuppGroups = getgroups(0, NULL);
     jfieldID fid;
     jstring jstr;
@@ -53,20 +59,31 @@
     gid_t *groups;
     jclass cls;
 
+    pwd_bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
+    if (pwd_bufsize == -1) {
+        pwd_bufsize = 1024;
+    }
+    pwd_buf = (char *)malloc(pwd_bufsize);
     groups = (gid_t *)calloc(numSuppGroups, sizeof(gid_t));
 
-    if (groups == NULL) {
-        jclass cls = (*env)->FindClass(env,"java/lang/OutOfMemoryError");
-        if (cls != NULL)
+    if (pwd_buf == NULL || groups == NULL) {
+        if (pwd_buf != NULL) {
+            free(pwd_buf);
+        }
+        if (groups != NULL) {
+            free(groups);
+        }
+        cls = (*env)->FindClass(env,"java/lang/OutOfMemoryError");
+        if (cls != NULL) {
             (*env)->ThrowNew(env, cls, NULL);
+        }
         return;
     }
 
     cls = (*env)->GetObjectClass(env, obj);
 
-    memset(pwd_buf, 0, sizeof(pwd_buf));
-    if (getpwuid_r(getuid(), &pwd, pwd_buf, sizeof(pwd_buf)) != NULL &&
-        getgroups(numSuppGroups, groups) != -1) {
+    if (getpwuid_r(getuid(), &pwd, pwd_buf, sizeof(pwd_buf), &p) != 0 &&
+        p != NULL && getgroups(numSuppGroups, groups) != -1) {
 
         /*
          * set username
@@ -129,7 +146,7 @@
         (*env)->SetObjectField(env, obj, fid, jgroups);
     }
 cleanupAndReturn:
+    free(pwd_buf);
     free(groups);
-
     return;
 }
--- a/jdk/src/jdk.security.auth/unix/native/libjaas/Unix.c	Fri Jul 15 09:10:36 2016 -0700
+++ b/jdk/src/jdk.security.auth/unix/native/libjaas/Unix.c	Fri Jul 15 18:09:33 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2016, 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
@@ -23,20 +23,21 @@
  * questions.
  */
 
-#ifdef __solaris__
-#define _POSIX_C_SOURCE 199506L
-#endif
-
 #include <jni.h>
 #include "jni_util.h"
 #include "com_sun_security_auth_module_UnixSystem.h"
 #include <stdio.h>
-#include <pwd.h>
 #include <sys/types.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
 
+/* For POSIX-compliant getpwuid_r on Solaris */
+#if defined(__solaris__)
+#define _POSIX_PTHREAD_SEMANTICS
+#endif
+#include <pwd.h>
+
 /*
  * Declare library specific JNI_Onload entry if static build
  */