diff --git a/jdk/src/java.base/unix/native/libjava/ProcessHandleImpl_unix.c b/jdk/src/java.base/unix/native/libjava/ProcessHandleImpl_unix.c index afbe1e275ee..4dc20ad084d 100644 --- a/jdk/src/java.base/unix/native/libjava/ProcessHandleImpl_unix.c +++ b/jdk/src/java.base/unix/native/libjava/ProcessHandleImpl_unix.c @@ -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 #include #include -#include #include #include #include @@ -46,6 +45,12 @@ #include #include +/* For POSIX-compliant getpwuid_r on Solaris */ +#if defined(__solaris__) +#define _POSIX_PTHREAD_SEMANTICS +#endif +#include + #ifdef _AIX #include #endif @@ -468,12 +473,7 @@ void unix_getUserInfo(JNIEnv* env, jobject jinfo, uid_t uid) { } 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 && diff --git a/jdk/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c b/jdk/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c index fe203cdf2dc..81b37db572f 100644 --- a/jdk/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c +++ b/jdk/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c @@ -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 #include #include -#include -#include #include #include #include @@ -43,6 +41,13 @@ #endif #include +/* For POSIX-compliant getpwuid_r, getgrgid_r on Solaris */ +#if defined(__solaris__) +#define _POSIX_PTHREAD_SEMANTICS +#endif +#include +#include + #ifdef __solaris__ #include #endif @@ -1022,11 +1027,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_getpwuid(JNIEnv* env, jclass this, jint uid 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 @@ Java_sun_nio_fs_UnixNativeDispatcher_getgrgid(JNIEnv* env, jclass this, jint gid } 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 @@ Java_sun_nio_fs_UnixNativeDispatcher_getpwnam0(JNIEnv* env, jclass this, 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 @@ Java_sun_nio_fs_UnixNativeDispatcher_getgrnam0(JNIEnv* env, jclass this, } 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') { diff --git a/jdk/src/jdk.security.auth/solaris/native/libjaas/Solaris.c b/jdk/src/jdk.security.auth/solaris/native/libjaas/Solaris.c index 1d251a65656..438b3b7318d 100644 --- a/jdk/src/jdk.security.auth/solaris/native/libjaas/Solaris.c +++ b/jdk/src/jdk.security.auth/solaris/native/libjaas/Solaris.c @@ -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 #include "com_sun_security_auth_module_SolarisSystem.h" #include -#include #include #include #include + +/* For POSIX-compliant getpwuid_r on Solaris */ +#if defined(__solaris__) +#define _POSIX_PTHREAD_SEMANTICS +#endif #include static void throwIllegalArgumentException(JNIEnv *env, const char *msg) { @@ -43,8 +47,10 @@ Java_com_sun_security_auth_module_SolarisSystem_getSolarisInfo (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 @@ Java_com_sun_security_auth_module_SolarisSystem_getSolarisInfo 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 @@ Java_com_sun_security_auth_module_SolarisSystem_getSolarisInfo (*env)->SetObjectField(env, obj, fid, jgroups); } cleanupAndReturn: + free(pwd_buf); free(groups); - return; } diff --git a/jdk/src/jdk.security.auth/unix/native/libjaas/Unix.c b/jdk/src/jdk.security.auth/unix/native/libjaas/Unix.c index 76737ab76a3..fdee7d3b935 100644 --- a/jdk/src/jdk.security.auth/unix/native/libjaas/Unix.c +++ b/jdk/src/jdk.security.auth/unix/native/libjaas/Unix.c @@ -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 #include "jni_util.h" #include "com_sun_security_auth_module_UnixSystem.h" #include -#include #include #include #include #include +/* For POSIX-compliant getpwuid_r on Solaris */ +#if defined(__solaris__) +#define _POSIX_PTHREAD_SEMANTICS +#endif +#include + /* * Declare library specific JNI_Onload entry if static build */