8013736: [launcher] cleanup code for correctness
8005735: [parfait] False positive integer overflow in jdk/src/solaris/bin/jexec.c
8009873: [parfait] Memory leak at jdk/src/share/bin/wildcard.c
8005807: [parfait] Undefined return value at jdk/src/share/bin/java.c
Reviewed-by: alanb, martin
--- a/jdk/src/share/bin/java.c Wed May 08 18:00:10 2013 +0100
+++ b/jdk/src/share/bin/java.c Tue May 07 13:15:28 2013 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2013, 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
@@ -149,12 +149,15 @@
static void FreeKnownVMs();
static jboolean IsWildCardEnabled();
-#define ARG_CHECK(n, f, a) if (n < 1) { \
- JLI_ReportErrorMessage(f, a); \
- printUsage = JNI_TRUE; \
- *pret = 1; \
- return JNI_TRUE; \
-}
+#define ARG_CHECK(AC_arg_count, AC_failure_message, AC_questionable_arg) \
+ do { \
+ if (AC_arg_count < 1) { \
+ JLI_ReportErrorMessage(AC_failure_message, AC_questionable_arg); \
+ printUsage = JNI_TRUE; \
+ *pret = 1; \
+ return JNI_TRUE; \
+ } \
+ } while (JNI_FALSE)
/*
* Running Java code in primordial thread caused many problems. We will
@@ -310,29 +313,37 @@
* mainThread.isAlive() to work as expected.
*/
#define LEAVE() \
- if ((*vm)->DetachCurrentThread(vm) != 0) { \
- JLI_ReportErrorMessage(JVM_ERROR2); \
- ret = 1; \
- } \
- (*vm)->DestroyJavaVM(vm); \
- return ret \
+ do { \
+ if ((*vm)->DetachCurrentThread(vm) != JNI_OK) { \
+ JLI_ReportErrorMessage(JVM_ERROR2); \
+ ret = 1; \
+ } \
+ if (JNI_TRUE) { \
+ (*vm)->DestroyJavaVM(vm); \
+ return ret; \
+ } \
+ } while (JNI_FALSE)
-#define CHECK_EXCEPTION_NULL_LEAVE(e) \
- if ((*env)->ExceptionOccurred(env)) { \
- JLI_ReportExceptionDescription(env); \
- LEAVE(); \
- } \
- if ((e) == NULL) { \
- JLI_ReportErrorMessage(JNI_ERROR); \
- LEAVE(); \
- }
+#define CHECK_EXCEPTION_NULL_LEAVE(CENL_exception) \
+ do { \
+ if ((*env)->ExceptionOccurred(env)) { \
+ JLI_ReportExceptionDescription(env); \
+ LEAVE(); \
+ } \
+ if ((CENL_exception) == NULL) { \
+ JLI_ReportErrorMessage(JNI_ERROR); \
+ LEAVE(); \
+ } \
+ } while (JNI_FALSE)
-#define CHECK_EXCEPTION_LEAVE(rv) \
- if ((*env)->ExceptionOccurred(env)) { \
- JLI_ReportExceptionDescription(env); \
- ret = (rv); \
- LEAVE(); \
- }
+#define CHECK_EXCEPTION_LEAVE(CEL_return_value) \
+ do { \
+ if ((*env)->ExceptionOccurred(env)) { \
+ JLI_ReportExceptionDescription(env); \
+ ret = (CEL_return_value); \
+ LEAVE(); \
+ } \
+ } while (JNI_FALSE)
int JNICALL
JavaMain(void * _args)
@@ -434,7 +445,7 @@
* consistent in the UI we need to track and report the application main class.
*/
appClass = GetApplicationClass(env);
- NULL_CHECK(appClass);
+ NULL_CHECK_RETURN_VALUE(appClass, -1);
/*
* PostJVMInit uses the class name as the application name for GUI purposes,
* for example, on OSX this sets the application name in the menu bar for
--- a/jdk/src/share/bin/java.h Wed May 08 18:00:10 2013 +0100
+++ b/jdk/src/share/bin/java.h Tue May 07 13:15:28 2013 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2013, 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
@@ -242,14 +242,18 @@
InvocationFunctions ifn;
} JavaMainArgs;
-#define NULL_CHECK0(e) if ((e) == 0) { \
- JLI_ReportErrorMessage(JNI_ERROR); \
- return 0; \
- }
+#define NULL_CHECK_RETURN_VALUE(NCRV_check_pointer, NCRV_return_value) \
+ do { \
+ if ((NCRV_check_pointer) == NULL) { \
+ JLI_ReportErrorMessage(JNI_ERROR); \
+ return NCRV_return_value; \
+ } \
+ } while (JNI_FALSE)
-#define NULL_CHECK(e) if ((e) == 0) { \
- JLI_ReportErrorMessage(JNI_ERROR); \
- return; \
- }
+#define NULL_CHECK0(NC0_check_pointer) \
+ NULL_CHECK_RETURN_VALUE(NC0_check_pointer, 0)
+
+#define NULL_CHECK(NC_check_pointer) \
+ NULL_CHECK_RETURN_VALUE(NC_check_pointer, )
#endif /* _JAVA_H_ */
--- a/jdk/src/share/bin/wildcard.c Wed May 08 18:00:10 2013 +0100
+++ b/jdk/src/share/bin/wildcard.c Tue May 07 13:15:28 2013 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2013, 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
@@ -136,8 +136,10 @@
{
WildcardIterator it = NEW_(WildcardIterator);
HANDLE handle = FindFirstFile(wildcard, &find_data);
- if (handle == INVALID_HANDLE_VALUE)
+ if (handle == INVALID_HANDLE_VALUE) {
+ JLI_MemFree(it);
return NULL;
+ }
it->handle = handle;
it->firstFile = find_data.cFileName;
return it;
--- a/jdk/src/solaris/bin/jexec.c Wed May 08 18:00:10 2013 +0100
+++ b/jdk/src/solaris/bin/jexec.c Tue May 07 13:15:28 2013 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2013, 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
@@ -90,6 +90,8 @@
static const char * BAD_EXEC_MSG = "jexec failed";
static const char * CRAZY_EXEC_MSG = "missing args";
static const char * MISSING_JAVA_MSG = "can't locate java";
+static const char * BAD_ARG_MSG = "incorrect number of arguments";
+static const char * MEM_FAILED_MSG = "memory allocation failed";
#ifdef __linux__
static const char * BAD_PATHNAME_MSG = "invalid path";
static const char * BAD_FILE_MSG = "invalid file";
@@ -156,6 +158,7 @@
const char ** nargv = NULL; /* new args array */
int nargc = 0; /* new args array count */
int argi = 0; /* index into old array */
+ size_t alen = 0; /* length of new array */
/* Make sure we have something to work with */
if ((argc < 1) || (argv == NULL)) {
@@ -168,8 +171,14 @@
if (getJavaPath(argv[argi++], java, RELATIVE_DEPTH) != 0) {
errorExit(errno, MISSING_JAVA_MSG);
}
-
- nargv = (const char **) malloc((argc + 2) * (sizeof (const char *)));
+ alen = (argc + 2) * (sizeof (const char *));
+ if (alen <= 0 || alen > INT_MAX / sizeof(char *)) {
+ errorExit(errno, BAD_ARG_MSG);
+ }
+ nargv = (const char **) malloc(alen);
+ if (nargv == NULL) {
+ errorExit(errno, MEM_FAILED_MSG);
+ }
nargv[nargc++] = java;
#ifdef __linux__