8212531: Several checks in native jpackager code
Submitten-by: almatvee
Reviewed-by: herrick
--- a/src/jdk.packager/macosx/native/library/MacPlatform.mm Thu Oct 18 21:04:15 2018 -0400
+++ b/src/jdk.packager/macosx/native/library/MacPlatform.mm Fri Oct 19 08:57:13 2018 -0400
@@ -264,6 +264,9 @@
// uses unless a packager config file exists.
ISectionalPropertyContainer* MacPlatform::GetConfigFile(TString FileName) {
IniFile* result = new IniFile();
+ if (result == NULL) {
+ return NULL;
+ }
if (UsePListForConfigFile() == false) {
if (result->LoadFromFile(FileName) == false) {
--- a/src/jdk.packager/share/classes/jdk/packager/internal/resources/StandardBundlerParam.properties Thu Oct 18 21:04:15 2018 -0400
+++ b/src/jdk.packager/share/classes/jdk/packager/internal/resources/StandardBundlerParam.properties Fri Oct 19 08:57:13 2018 -0400
@@ -87,6 +87,9 @@
param.name.name=Name
param.name.description=The name of the application.
+param.preferences-id.name=Preferences ID
+param.preferences-id.description=The preferences node to search for User JVM Options. The format be a slash delimited version of the main package name, such as "com/example/myapplication".
+
param.title.name=Title
param.title.description=A title for the application.
--- a/src/jdk.packager/share/classes/jdk/packager/internal/resources/StandardBundlerParam_ja.properties Thu Oct 18 21:04:15 2018 -0400
+++ b/src/jdk.packager/share/classes/jdk/packager/internal/resources/StandardBundlerParam_ja.properties Fri Oct 19 08:57:13 2018 -0400
@@ -88,6 +88,9 @@
param.main-jar.name=\u30E1\u30A4\u30F3Jar
param.main-jar.description=\u30A2\u30D7\u30EA\u30B1\u30FC\u30B7\u30E7\u30F3\u306E\u30E1\u30A4\u30F3jar\u3002\u3053\u306Ejar\u306Fmain-class\u3092\u6301\u3064\u5FC5\u8981\u304C\u3042\u308A\u3001\u30A2\u30BB\u30F3\u30D6\u30EB\u3055\u308C\u305F\u30A2\u30D7\u30EA\u30B1\u30FC\u30B7\u30E7\u30F3\u30FB\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u306B\u5BFE\u3057\u3066\u76F8\u5BFE\u7684\u3067\u3059\u3002
+param.preferences-id.name=\u30D7\u30EA\u30D5\u30A1\u30EC\u30F3\u30B9ID
+param.preferences-id.description=\u30E6\u30FC\u30B6\u30FC\u306EJVM\u30AA\u30D7\u30B7\u30E7\u30F3\u3092\u691C\u7D22\u3059\u308B\u30D7\u30EA\u30D5\u30A1\u30EC\u30F3\u30B9\u30FB\u30CE\u30FC\u30C9\u3002\u5F62\u5F0F\u306F\u3001"com/example/myapplication"\u306A\u3069\u3001\u30E1\u30A4\u30F3\u30FB\u30D1\u30C3\u30B1\u30FC\u30B8\u540D\u306E\u30B9\u30E9\u30C3\u30B7\u30E5\u533A\u5207\u308A\u30D0\u30FC\u30B8\u30E7\u30F3\u3067\u3059\u3002
+
param.sign-bundle.name=\u7F72\u540D\u30D0\u30F3\u30C9\u30EB
param.sign-bundle.description=\u30D0\u30F3\u30C9\u30E9\u304C\u7F72\u540D\u3092\u30B5\u30DD\u30FC\u30C8\u3057\u3066\u3044\u308B\u5834\u5408\u3001\u30D0\u30F3\u30C9\u30EB\u304C\u7F72\u540D\u3055\u308C\u3066\u3044\u308B\u3053\u3068\u3092\u8981\u6C42\u3057\u307E\u3059\u3002\u30C7\u30D5\u30A9\u30EB\u30C8\u5024\u306F\u30D0\u30F3\u30C9\u30E9\u306B\u3088\u3063\u3066\u7570\u306A\u308A\u307E\u3059\u3002\u7F72\u540D\u3092\u30B5\u30DD\u30FC\u30C8\u3057\u3066\u3044\u306A\u3044\u30D0\u30F3\u30C9\u30E9\u3067\u306F\u3001\u3053\u306E\u8A2D\u5B9A\u306F\u8B66\u544A\u306A\u3057\u3067\u7121\u8996\u3055\u308C\u307E\u3059\u3002
--- a/src/jdk.packager/share/classes/jdk/packager/internal/resources/StandardBundlerParam_zh_CN.properties Thu Oct 18 21:04:15 2018 -0400
+++ b/src/jdk.packager/share/classes/jdk/packager/internal/resources/StandardBundlerParam_zh_CN.properties Fri Oct 19 08:57:13 2018 -0400
@@ -88,6 +88,9 @@
param.main-jar.name=\u4E3B Jar
param.main-jar.description=\u5E94\u7528\u7A0B\u5E8F\u7684\u4E3B jar\u3002\u6B64 jar \u5E94\u5177\u6709\u4E3B\u7C7B, \u5E76\u4E14\u76F8\u5BF9\u4E8E\u7EC4\u5408\u7684\u5E94\u7528\u7A0B\u5E8F\u76EE\u5F55\u3002
+param.preferences-id.name=\u9996\u9009 ID
+param.preferences-id.description=\u5728\u5176\u4E2D\u641C\u7D22\u7528\u6237 JVM \u9009\u9879\u7684\u9996\u9009\u8282\u70B9\u3002\u5176\u683C\u5F0F\u5E94\u4E3A\u4E3B\u7A0B\u5E8F\u5305\u540D\u79F0\u4EE5\u659C\u6760\u5206\u9694\u7684\u7248\u672C, \u4F8B\u5982 "com/example/myapplication"\u3002
+
param.sign-bundle.name=\u5BF9\u5305\u7B7E\u540D
param.sign-bundle.description=\u5982\u679C\u6253\u5305\u7A0B\u5E8F\u652F\u6301\u7B7E\u540D, \u5219\u8BF7\u6C42\u5BF9\u5305\u7B7E\u540D\u3002\u9ED8\u8BA4\u503C\u56E0\u6253\u5305\u7A0B\u5E8F\u800C\u5F02\u3002\u4E0D\u652F\u6301\u7B7E\u540D\u7684\u6253\u5305\u7A0B\u5E8F\u5C06\u65E0\u63D0\u793A\u5FFD\u7565\u6B64\u8BBE\u7F6E\u3002
--- a/src/jdk.packager/share/native/library/common/FilePath.cpp Thu Oct 18 21:04:15 2018 -0400
+++ b/src/jdk.packager/share/native/library/common/FilePath.cpp Fri Oct 19 08:57:13 2018 -0400
@@ -148,6 +148,9 @@
SHFILEOPSTRUCTW fos = {0};
TString directoryName = FixPathForPlatform(DirectoryName);
DynamicBuffer<TCHAR> lDirectoryName(directoryName.size() + 2);
+ if (lDirectoryName.GetData() == NULL) {
+ return false;
+ }
memcpy(lDirectoryName.GetData(), directoryName.data(), (directoryName.size() + 2) * sizeof(TCHAR));
lDirectoryName[directoryName.size() + 1] = NULL;
// Double null terminate for SHFileOperation.
--- a/src/jdk.packager/share/native/library/common/Helpers.cpp Thu Oct 18 21:04:15 2018 -0400
+++ b/src/jdk.packager/share/native/library/common/Helpers.cpp Fri Oct 19 08:57:13 2018 -0400
@@ -253,24 +253,6 @@
}
}
-void Helpers::LoadOldUserConfigFile(TString FileName, IniFile* Container) {
- PropertyFile propertyFile;
- Container = NULL;
-
- if (propertyFile.LoadFromFile(FileName) == true) {
- Container = new IniFile();
- Platform& platform = Platform::GetInstance();
-
- std::map<TString, TString> keys = platform.GetKeys();
-
- // JVMUserOverridesOptions Section
- OrderedMap<TString, TString> defaultJVMUserArgs =
- Helpers::GetJVMUserArgsFromConfig(&propertyFile);
- Container->AppendSection(keys[CONFIG_SECTION_JVMUSEROVERRIDESOPTIONS],
- defaultJVMUserArgs);
- }
-}
-
std::list<TString>
Helpers::MapToNameValueList(OrderedMap<TString, TString> Map) {
std::list<TString> result;
@@ -292,7 +274,6 @@
return result;
}
-
TString Helpers::NameValueToString(TString name, TString value) {
TString result;
--- a/src/jdk.packager/share/native/library/common/Helpers.h Thu Oct 18 21:04:15 2018 -0400
+++ b/src/jdk.packager/share/native/library/common/Helpers.h Fri Oct 19 08:57:13 2018 -0400
@@ -58,7 +58,6 @@
static std::list<TString> GetArgsFromConfig(IPropertyContainer* config);
static void LoadOldConfigFile(TString FileName, IniFile* Container);
- static void LoadOldUserConfigFile(TString FileName, IniFile* Container);
static std::list<TString>
MapToNameValueList(OrderedMap<TString, TString> Map);
--- a/src/jdk.packager/share/native/library/common/JavaVirtualMachine.cpp Thu Oct 18 21:04:15 2018 -0400
+++ b/src/jdk.packager/share/native/library/common/JavaVirtualMachine.cpp Fri Oct 19 08:57:13 2018 -0400
@@ -390,6 +390,10 @@
size_t argc = vmargs.size();
DynamicBuffer<char*> argv(argc + 1);
+ if (argv.GetData() == NULL) {
+ return false;
+ }
+
unsigned int index = 0;
for (std::list<TString>::const_iterator iterator = vmargs.begin();
iterator != vmargs.end(); iterator++) {
--- a/src/jdk.packager/share/native/library/common/LinuxPlatform.cpp Thu Oct 18 21:04:15 2018 -0400
+++ b/src/jdk.packager/share/native/library/common/LinuxPlatform.cpp Fri Oct 19 08:57:13 2018 -0400
@@ -93,6 +93,9 @@
ssize_t len = 0;
TString result;
DynamicBuffer<TCHAR> buffer(MAX_PATH);
+ if (buffer.GetData() == NULL) {
+ return result;
+ }
if ((len = readlink("/proc/self/exe", buffer.GetData(),
MAX_PATH - 1)) != -1) {
@@ -125,6 +128,9 @@
ISectionalPropertyContainer* LinuxPlatform::GetConfigFile(TString FileName) {
IniFile *result = new IniFile();
+ if (result == NULL) {
+ return NULL;
+ }
if (result->LoadFromFile(FileName) == false) {
// New property file format was not found,
@@ -1055,16 +1061,18 @@
OrderedMap<TString, TString> GetJvmUserArgs(TString filename) {
OrderedMap<TString, TString> result;
+ DynamicBuffer<char> buffer(fsize + 1);
+ if (buffer.GetData() == NULL) {
+ return result;
+ }
if (FilePath::FileExists(filename) == true) {
//scan file for the key
FILE* fp = fopen(PlatformString(filename).toPlatformString(), "r");
-
if (fp != NULL) {
fseek(fp, 0, SEEK_END);
long fsize = ftell(fp);
rewind(fp);
- DynamicBuffer<char> buffer(fsize + 1);
fread(buffer.GetData(), fsize, 1, fp);
fclose(fp);
buffer[fsize] = 0;
--- a/src/jdk.packager/share/native/library/common/PlatformString.h Thu Oct 18 21:04:15 2018 -0400
+++ b/src/jdk.packager/share/native/library/common/PlatformString.h Fri Oct 19 08:57:13 2018 -0400
@@ -71,7 +71,7 @@
T* GetData() { return FData; }
size_t GetSize() { return FSize; }
- void Resize(size_t Size) {
+ bool Resize(size_t Size) {
FSize = Size;
if (FData != NULL) {
@@ -83,8 +83,12 @@
FData = new T[FSize];
if (FData != NULL) {
Zero();
+ } else {
+ return false;
}
}
+
+ return true;
}
void Zero() {
--- a/src/jdk.packager/share/native/library/common/WindowsPlatform.cpp Thu Oct 18 21:04:15 2018 -0400
+++ b/src/jdk.packager/share/native/library/common/WindowsPlatform.cpp Fri Oct 19 08:57:13 2018 -0400
@@ -85,6 +85,9 @@
DWORD length = 255;
DynamicBuffer<TCHAR> buffer(length);
+ if (buffer.GetData() == NULL) {
+ return result;
+ }
for (unsigned int index = 0; index < count; index++) {
buffer.Zero();
@@ -93,7 +96,9 @@
while (status == ERROR_MORE_DATA) {
length = length * 2;
- buffer.Resize(length);
+ if (!buffer.Resize(length)) {
+ return result;
+ }
status = RegEnumValue(FOpenKey, index, buffer.GetData(),
&length, NULL, NULL, NULL, NULL);
}
@@ -118,7 +123,9 @@
dwRet = RegQueryValueEx(FOpenKey, Name.data(), NULL, NULL, NULL,
&length);
if (dwRet == ERROR_MORE_DATA || dwRet == 0) {
- buffer.Resize(length + 1);
+ if (!buffer.Resize(length + 1)) {
+ return result;
+ }
dwRet = RegQueryValueEx(FOpenKey, Name.data(), NULL, NULL,
(LPBYTE)buffer.GetData(), &length);
result = buffer.GetData();
@@ -205,6 +212,9 @@
ISectionalPropertyContainer* WindowsPlatform::GetConfigFile(TString FileName) {
IniFile *result = new IniFile();
+ if (result == NULL) {
+ return NULL;
+ }
if (result->LoadFromFile(FileName) == false) {
// New property file format was not found,
@@ -218,11 +228,17 @@
TString WindowsPlatform::GetModuleFileName() {
TString result;
DynamicBuffer<wchar_t> buffer(MAX_PATH);
+ if (buffer.GetData() == NULL) {
+ return result;
+ }
+
::GetModuleFileName(NULL, buffer.GetData(),
static_cast<DWORD>(buffer.GetSize()));
while (ERROR_INSUFFICIENT_BUFFER == GetLastError()) {
- buffer.Resize(buffer.GetSize() * 2);
+ if (!buffer.Resize(buffer.GetSize() * 2)) {
+ return result;
+ }
::GetModuleFileName(NULL, buffer.GetData(),
static_cast<DWORD>(buffer.GetSize()));
}
@@ -826,6 +842,10 @@
bool result = false;
HANDLE handle = ::CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
+ if (handle == INVALID_HANDLE_VALUE) {
+ return false;
+ }
+
PROCESSENTRY32 process = { 0 };
process.dwSize = sizeof(process);