[SERVICES]
authorEric Kohl <eric.kohl@reactos.org>
Wed, 9 Nov 2011 23:18:37 +0000 (23:18 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Wed, 9 Nov 2011 23:18:37 +0000 (23:18 +0000)
Improve the parameter checks in RCreateServiceW.

svn path=/trunk/; revision=54342

reactos/base/system/services/rpcserver.c

index 6aaa427..e25e8e0 100644 (file)
@@ -1999,26 +1999,39 @@ DWORD RCreateServiceW(
         return ERROR_INVALID_PARAMETER;
     }
 
-    if ((dwServiceType & SERVICE_KERNEL_DRIVER) &&
-        (dwServiceType & SERVICE_FILE_SYSTEM_DRIVER))
-    {
+    /* Check for invalid service type value */
+    if ((dwServiceType != SERVICE_KERNEL_DRIVER) &&
+        (dwServiceType != SERVICE_FILE_SYSTEM_DRIVER) &&
+        ((dwServiceType & ~SERVICE_INTERACTIVE_PROCESS) != SERVICE_WIN32_OWN_PROCESS) &&
+        ((dwServiceType & ~SERVICE_INTERACTIVE_PROCESS) != SERVICE_WIN32_SHARE_PROCESS))
+            return ERROR_INVALID_PARAMETER;
+
+    /* Check for invalid start type value */
+    if ((dwStartType != SERVICE_BOOT_START) &&
+        (dwStartType != SERVICE_SYSTEM_START) &&
+        (dwStartType != SERVICE_AUTO_START) &&
+        (dwStartType != SERVICE_DEMAND_START) &&
+        (dwStartType != SERVICE_DISABLED))
         return ERROR_INVALID_PARAMETER;
-    }
 
-    if ((dwServiceType == (SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS)) &&
-        (lpServiceStartName))
+    /* Only drivers can be boot start or system start services */
+    if ((dwStartType == SERVICE_BOOT_START) ||
+        (dwStartType == SERVICE_SYSTEM_START))
     {
-        return ERROR_INVALID_PARAMETER;
+        if ((dwServiceType != SERVICE_KERNEL_DRIVER) &&
+            (dwServiceType != SERVICE_FILE_SYSTEM_DRIVER))
+            return ERROR_INVALID_PARAMETER;
     }
 
-    if ((dwServiceType > SERVICE_WIN32_SHARE_PROCESS) &&
-        (dwServiceType != (SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS)) &&
-        (dwServiceType != (SERVICE_WIN32_SHARE_PROCESS | SERVICE_INTERACTIVE_PROCESS)))
-    {
+    /* Check for invalid error control value */
+    if ((dwErrorControl != SERVICE_ERROR_IGNORE) &&
+        (dwErrorControl != SERVICE_ERROR_NORMAL) &&
+        (dwErrorControl != SERVICE_ERROR_SEVERE) &&
+        (dwErrorControl != SERVICE_ERROR_CRITICAL))
         return ERROR_INVALID_PARAMETER;
-    }
 
-    if (dwStartType > SERVICE_DISABLED)
+    if ((dwServiceType == (SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS)) &&
+        (lpServiceStartName))
     {
         return ERROR_INVALID_PARAMETER;
     }