Be less paranoid.
authorIain Patterson <me@iain.cx>
Tue, 26 Nov 2013 11:13:42 +0000 (11:13 +0000)
committerIain Patterson <me@iain.cx>
Tue, 26 Nov 2013 20:38:04 +0000 (20:38 +0000)
We were checking that the path to our executable was within MAX_PATH but
it must be by definition and we have been safely skipping the check
elsewhere.

service.cpp

index fc9b73c..294497a 100644 (file)
@@ -142,20 +142,8 @@ int install_service(nssm_service_t *service) {
   }\r
 \r
   /* Get path of this program */\r
-  TCHAR path[MAX_PATH];\r
-  GetModuleFileName(0, path, MAX_PATH);\r
-\r
-  /* Construct command */\r
-  TCHAR command[CMD_LENGTH];\r
-  size_t pathlen = _tcslen(path);\r
-  if (pathlen + 1 >= VALUE_LENGTH) {\r
-    print_message(stderr, NSSM_MESSAGE_PATH_TOO_LONG, NSSM);\r
-    return 3;\r
-  }\r
-  if (_sntprintf_s(command, sizeof(command), _TRUNCATE, _T("\"%s\""), path) < 0) {\r
-    print_message(stderr, NSSM_MESSAGE_OUT_OF_MEMORY_FOR_IMAGEPATH);\r
-    return 4;\r
-  }\r
+  TCHAR command[MAX_PATH];\r
+  GetModuleFileName(0, command, _countof(command));\r
 \r
   /* Create the service */\r
   service->handle = CreateService(services, service->name, service->name, SC_MANAGER_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, command, 0, 0, 0, 0, 0);\r