From 06feee380605729214a66c280adbaec98e98c890 Mon Sep 17 00:00:00 2001 From: bchristi Date: Fri, 13 Sep 2013 11:26:44 -0700 Subject: [PATCH] 7199674: (props) user.home property does not return an accessible location in sandboxed environment [macosx] Summary: On MacOS X set user.home to value of NSHomeDirectory() Reviewed-by: alanb, ddehaven, mduigou --- make/common/Defs-macosx.gmk | 10 ++++------ make/java/java/Makefile | 1 + makefiles/CompileNativeLibraries.gmk | 2 ++ src/solaris/native/java/lang/java_props_macosx.c | 14 +++++++++++++- src/solaris/native/java/lang/java_props_macosx.h | 1 + src/solaris/native/java/lang/java_props_md.c | 9 ++++++++- 6 files changed, 29 insertions(+), 8 deletions(-) diff --git a/make/common/Defs-macosx.gmk b/make/common/Defs-macosx.gmk index 1b7aaa8ae..befd2cfed 100644 --- a/make/common/Defs-macosx.gmk +++ b/make/common/Defs-macosx.gmk @@ -397,12 +397,10 @@ else INCLUDE_SA = true endif -ifdef CROSS_COMPILE_ARCH - # X11 headers are not under /usr/include - OTHER_CFLAGS += -I$(OPENWIN_HOME)/include - OTHER_CXXFLAGS += -I$(OPENWIN_HOME)/include - OTHER_CPPFLAGS += -I$(OPENWIN_HOME)/include -endif +# X11 headers are not under /usr/include +OTHER_CFLAGS += -I$(OPENWIN_HOME)/include +OTHER_CXXFLAGS += -I$(OPENWIN_HOME)/include +OTHER_CPPFLAGS += -I$(OPENWIN_HOME)/include LIB_LOCATION ?= $(LIBDIR) diff --git a/make/java/java/Makefile b/make/java/java/Makefile index 829cf9330..d2a663f9a 100644 --- a/make/java/java/Makefile +++ b/make/java/java/Makefile @@ -105,6 +105,7 @@ FILES_java += java/util/prefs/MacOSXPreferences.java \ java/util/prefs/MacOSXPreferencesFactory.java CFLAGS_$(VARIANT)/java_props_md.o = -Os -x objective-c +CFLAGS_$(VARIANT)/java_props_macosx.o = -Os -x objective-c endif # diff --git a/makefiles/CompileNativeLibraries.gmk b/makefiles/CompileNativeLibraries.gmk index 656ee3c48..d507c92a5 100644 --- a/makefiles/CompileNativeLibraries.gmk +++ b/makefiles/CompileNativeLibraries.gmk @@ -211,6 +211,7 @@ ifneq ($(OPENJDK_TARGET_OS),macosx) LIBJAVA_EXCLUDE_FILES += java_props_macosx.c else BUILD_LIBJAVA_java_props_md.c_CFLAGS:=-x objective-c + BUILD_LIBJAVA_java_props_macosx.c_CFLAGS:=-x objective-c endif ifeq ($(OPENJDK_TARGET_OS),windows) @@ -252,6 +253,7 @@ $(eval $(call SetupNativeCompilation,BUILD_LIBJAVA,\ LDFLAGS_SUFFIX_linux:=$(LIBDL) $(BUILD_LIBFDLIBM),\ LDFLAGS_SUFFIX_macosx:=-L$(JDK_OUTPUTDIR)/objs/ -lfdlibm \ -framework CoreFoundation \ + -framework Foundation \ -framework Security -framework SystemConfiguration, \ LDFLAGS_SUFFIX_windows:=-export:winFileHandleOpen -export:handleLseek \ jvm.lib $(BUILD_LIBFDLIBM) $(WIN_VERIFY_LIB) \ diff --git a/src/solaris/native/java/lang/java_props_macosx.c b/src/solaris/native/java/lang/java_props_macosx.c index f9ad2e474..13fc80d30 100644 --- a/src/solaris/native/java/lang/java_props_macosx.c +++ b/src/solaris/native/java/lang/java_props_macosx.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "java_props_macosx.h" @@ -271,9 +272,20 @@ static char * createConvertedException(CFStringRef cf_original) { return c_exception; } +/* + * Method for fetching the user.home path and storing it in the property list. + * For signed .apps running in the Mac App Sandbox, user.home is set to the + * app's sandbox container. + */ +void setUserHome(java_props_t *sprops) { + if (sprops == NULL) { return; } + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + sprops->user_home = createUTF8CString((CFStringRef)NSHomeDirectory()); + [pool drain]; +} /* - * Method for fetching proxy info and storing it in the propery list. + * Method for fetching proxy info and storing it in the property list. */ void setProxyProperties(java_props_t *sProps) { if (sProps == NULL) return; diff --git a/src/solaris/native/java/lang/java_props_macosx.h b/src/solaris/native/java/lang/java_props_macosx.h index b31180483..19ec220ed 100644 --- a/src/solaris/native/java/lang/java_props_macosx.h +++ b/src/solaris/native/java/lang/java_props_macosx.h @@ -27,6 +27,7 @@ char *setupMacOSXLocale(int cat); void setOSNameAndVersion(java_props_t *sprops); +void setUserHome(java_props_t *sprops); void setProxyProperties(java_props_t *sProps); enum PreferredToolkit_enum { diff --git a/src/solaris/native/java/lang/java_props_md.c b/src/solaris/native/java/lang/java_props_md.c index 58e5e4543..dba053e8f 100644 --- a/src/solaris/native/java/lang/java_props_md.c +++ b/src/solaris/native/java/lang/java_props_md.c @@ -591,7 +591,14 @@ GetJavaProperties(JNIEnv *env) { struct passwd *pwent = getpwuid(getuid()); sprops.user_name = pwent ? strdup(pwent->pw_name) : "?"; - sprops.user_home = pwent ? strdup(pwent->pw_dir) : "?"; +#ifdef MACOSX + setUserHome(&sprops); +#else + sprops.user_home = pwent ? strdup(pwent->pw_dir) : NULL; +#endif + if (sprops.user_home == NULL) { + sprops.user_home = "?"; + } } /* User TIMEZONE */ -- GitLab