提交 fc9c54b2 编写于 作者: K ksrini

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
上级 1d607ad5
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -149,12 +149,15 @@ static int KnownVMIndex(const char* name); ...@@ -149,12 +149,15 @@ static int KnownVMIndex(const char* name);
static void FreeKnownVMs(); static void FreeKnownVMs();
static jboolean IsWildCardEnabled(); static jboolean IsWildCardEnabled();
#define ARG_CHECK(n, f, a) if (n < 1) { \ #define ARG_CHECK(AC_arg_count, AC_failure_message, AC_questionable_arg) \
JLI_ReportErrorMessage(f, a); \ do { \
printUsage = JNI_TRUE; \ if (AC_arg_count < 1) { \
*pret = 1; \ JLI_ReportErrorMessage(AC_failure_message, AC_questionable_arg); \
return JNI_TRUE; \ printUsage = JNI_TRUE; \
} *pret = 1; \
return JNI_TRUE; \
} \
} while (JNI_FALSE)
/* /*
* Running Java code in primordial thread caused many problems. We will * Running Java code in primordial thread caused many problems. We will
...@@ -310,29 +313,37 @@ JLI_Launch(int argc, char ** argv, /* main argc, argc */ ...@@ -310,29 +313,37 @@ JLI_Launch(int argc, char ** argv, /* main argc, argc */
* mainThread.isAlive() to work as expected. * mainThread.isAlive() to work as expected.
*/ */
#define LEAVE() \ #define LEAVE() \
if ((*vm)->DetachCurrentThread(vm) != 0) { \ do { \
JLI_ReportErrorMessage(JVM_ERROR2); \ if ((*vm)->DetachCurrentThread(vm) != JNI_OK) { \
ret = 1; \ JLI_ReportErrorMessage(JVM_ERROR2); \
} \ ret = 1; \
(*vm)->DestroyJavaVM(vm); \ } \
return ret \ if (JNI_TRUE) { \
(*vm)->DestroyJavaVM(vm); \
#define CHECK_EXCEPTION_NULL_LEAVE(e) \ return ret; \
if ((*env)->ExceptionOccurred(env)) { \ } \
JLI_ReportExceptionDescription(env); \ } while (JNI_FALSE)
LEAVE(); \
} \ #define CHECK_EXCEPTION_NULL_LEAVE(CENL_exception) \
if ((e) == NULL) { \ do { \
JLI_ReportErrorMessage(JNI_ERROR); \ if ((*env)->ExceptionOccurred(env)) { \
LEAVE(); \ JLI_ReportExceptionDescription(env); \
} LEAVE(); \
} \
#define CHECK_EXCEPTION_LEAVE(rv) \ if ((CENL_exception) == NULL) { \
if ((*env)->ExceptionOccurred(env)) { \ JLI_ReportErrorMessage(JNI_ERROR); \
JLI_ReportExceptionDescription(env); \ LEAVE(); \
ret = (rv); \ } \
LEAVE(); \ } while (JNI_FALSE)
}
#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 int JNICALL
JavaMain(void * _args) JavaMain(void * _args)
...@@ -434,7 +445,7 @@ JavaMain(void * _args) ...@@ -434,7 +445,7 @@ JavaMain(void * _args)
* consistent in the UI we need to track and report the application main class. * consistent in the UI we need to track and report the application main class.
*/ */
appClass = GetApplicationClass(env); appClass = GetApplicationClass(env);
NULL_CHECK(appClass); NULL_CHECK_RETURN_VALUE(appClass, -1);
/* /*
* PostJVMInit uses the class name as the application name for GUI purposes, * 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 * for example, on OSX this sets the application name in the menu bar for
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -242,14 +242,18 @@ typedef struct { ...@@ -242,14 +242,18 @@ typedef struct {
InvocationFunctions ifn; InvocationFunctions ifn;
} JavaMainArgs; } JavaMainArgs;
#define NULL_CHECK0(e) if ((e) == 0) { \ #define NULL_CHECK_RETURN_VALUE(NCRV_check_pointer, NCRV_return_value) \
JLI_ReportErrorMessage(JNI_ERROR); \ do { \
return 0; \ if ((NCRV_check_pointer) == NULL) { \
} JLI_ReportErrorMessage(JNI_ERROR); \
return NCRV_return_value; \
} \
} while (JNI_FALSE)
#define NULL_CHECK(e) if ((e) == 0) { \ #define NULL_CHECK0(NC0_check_pointer) \
JLI_ReportErrorMessage(JNI_ERROR); \ NULL_CHECK_RETURN_VALUE(NC0_check_pointer, 0)
return; \
} #define NULL_CHECK(NC_check_pointer) \
NULL_CHECK_RETURN_VALUE(NC_check_pointer, )
#endif /* _JAVA_H_ */ #endif /* _JAVA_H_ */
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -136,8 +136,10 @@ WildcardIterator_for(const char *wildcard) ...@@ -136,8 +136,10 @@ WildcardIterator_for(const char *wildcard)
{ {
WildcardIterator it = NEW_(WildcardIterator); WildcardIterator it = NEW_(WildcardIterator);
HANDLE handle = FindFirstFile(wildcard, &find_data); HANDLE handle = FindFirstFile(wildcard, &find_data);
if (handle == INVALID_HANDLE_VALUE) if (handle == INVALID_HANDLE_VALUE) {
JLI_MemFree(it);
return NULL; return NULL;
}
it->handle = handle; it->handle = handle;
it->firstFile = find_data.cFileName; it->firstFile = find_data.cFileName;
return it; return it;
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -90,6 +90,8 @@ static const int BAD_MAGIC = ENOEXEC; ...@@ -90,6 +90,8 @@ static const int BAD_MAGIC = ENOEXEC;
static const char * BAD_EXEC_MSG = "jexec failed"; static const char * BAD_EXEC_MSG = "jexec failed";
static const char * CRAZY_EXEC_MSG = "missing args"; static const char * CRAZY_EXEC_MSG = "missing args";
static const char * MISSING_JAVA_MSG = "can't locate java"; 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__ #ifdef __linux__
static const char * BAD_PATHNAME_MSG = "invalid path"; static const char * BAD_PATHNAME_MSG = "invalid path";
static const char * BAD_FILE_MSG = "invalid file"; static const char * BAD_FILE_MSG = "invalid file";
...@@ -156,6 +158,7 @@ int main(int argc, const char * argv[]) { ...@@ -156,6 +158,7 @@ int main(int argc, const char * argv[]) {
const char ** nargv = NULL; /* new args array */ const char ** nargv = NULL; /* new args array */
int nargc = 0; /* new args array count */ int nargc = 0; /* new args array count */
int argi = 0; /* index into old array */ int argi = 0; /* index into old array */
size_t alen = 0; /* length of new array */
/* Make sure we have something to work with */ /* Make sure we have something to work with */
if ((argc < 1) || (argv == NULL)) { if ((argc < 1) || (argv == NULL)) {
...@@ -168,8 +171,14 @@ int main(int argc, const char * argv[]) { ...@@ -168,8 +171,14 @@ int main(int argc, const char * argv[]) {
if (getJavaPath(argv[argi++], java, RELATIVE_DEPTH) != 0) { if (getJavaPath(argv[argi++], java, RELATIVE_DEPTH) != 0) {
errorExit(errno, MISSING_JAVA_MSG); errorExit(errno, MISSING_JAVA_MSG);
} }
alen = (argc + 2) * (sizeof (const char *));
nargv = (const char **) malloc((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; nargv[nargc++] = java;
#ifdef __linux__ #ifdef __linux__
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册