src/jdk.packager/share/native/library/common/WindowsPlatform.cpp
branchJDK-8200758-branch
changeset 56993 3629eb24e9ac
parent 56982 e094d5483bd6
child 56995 3d5b13207b70
--- 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);