Browse Source

service->passwordlen is a count of TCHARs, fix SecureZeroMemory for UNICODE

David Bremner 6 years ago
parent
commit
fe0f3a497b
2 changed files with 7 additions and 7 deletions
  1. 6 6
      gui.cpp
  2. 1 1
      service.cpp

+ 6 - 6
gui.cpp

@@ -450,7 +450,7 @@ int configure(HWND window, nssm_service_t *service, nssm_service_t *orig_service
     service->username = 0;
     service->usernamelen = 0;
     if (service->password) {
-      SecureZeroMemory(service->password, service->passwordlen);
+      SecureZeroMemory(service->password, service->passwordlen * sizeof(TCHAR));
       HeapFree(GetProcessHeap(), 0, service->password);
     }
     service->password = 0;
@@ -539,7 +539,7 @@ int configure(HWND window, nssm_service_t *service, nssm_service_t *orig_service
         /* Get first password. */
         if (! GetDlgItemText(tablist[NSSM_TAB_LOGON], IDC_PASSWORD1, service->password, (int) service->passwordlen)) {
           HeapFree(GetProcessHeap(), 0, password);
-          SecureZeroMemory(service->password, service->passwordlen);
+          SecureZeroMemory(service->password, service->passwordlen * sizeof(TCHAR));
           HeapFree(GetProcessHeap(), 0, service->password);
           service->password = 0;
           service->passwordlen = 0;
@@ -552,9 +552,9 @@ int configure(HWND window, nssm_service_t *service, nssm_service_t *orig_service
 
         /* Get confirmation. */
         if (! GetDlgItemText(tablist[NSSM_TAB_LOGON], IDC_PASSWORD2, password, (int) service->passwordlen)) {
-          SecureZeroMemory(password, service->passwordlen);
+          SecureZeroMemory(password, service->passwordlen * sizeof(TCHAR));
           HeapFree(GetProcessHeap(), 0, password);
-          SecureZeroMemory(service->password, service->passwordlen);
+          SecureZeroMemory(service->password, service->passwordlen * sizeof(TCHAR));
           HeapFree(GetProcessHeap(), 0, service->password);
           service->password = 0;
           service->passwordlen = 0;
@@ -568,9 +568,9 @@ int configure(HWND window, nssm_service_t *service, nssm_service_t *orig_service
         /* Compare. */
         if (_tcsncmp(password, service->password, service->passwordlen)) {
           popup_message(window, MB_OK | MB_ICONEXCLAMATION, NSSM_GUI_MISSING_PASSWORD);
-          SecureZeroMemory(password, service->passwordlen);
+          SecureZeroMemory(password, service->passwordlen * sizeof(TCHAR));
           HeapFree(GetProcessHeap(), 0, password);
-          SecureZeroMemory(service->password, service->passwordlen);
+          SecureZeroMemory(service->password, service->passwordlen * sizeof(TCHAR));
           HeapFree(GetProcessHeap(), 0, service->password);
           service->password = 0;
           service->passwordlen = 0;

+ 1 - 1
service.cpp

@@ -760,7 +760,7 @@ void cleanup_nssm_service(nssm_service_t *service) {
   if (! service) return;
   if (service->username) HeapFree(GetProcessHeap(), 0, service->username);
   if (service->password) {
-    SecureZeroMemory(service->password, service->passwordlen);
+    SecureZeroMemory(service->password, service->passwordlen * sizeof(TCHAR));
     HeapFree(GetProcessHeap(), 0, service->password);
   }
   if (service->dependencies) HeapFree(GetProcessHeap(), 0, service->dependencies);