[USERENV] Check for invalid parameters in Get{Profiles,UserProfile}Directory{A,W...
[reactos.git] / reactos / dll / win32 / userenv / profile.c
index 888115b..68d3716 100644 (file)
 
 #include "precomp.h"
 
+#include <sddl.h>
+
 #define NDEBUG
 #include <debug.h>
 
-
 /* FUNCTIONS ***************************************************************/
 
 BOOL
@@ -671,6 +672,12 @@ GetProfilesDirectoryA(LPSTR lpProfileDir,
     LPWSTR lpBuffer;
     BOOL bResult;
 
+    if (!lpProfileDir || !lpcchSize)
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
+
     lpBuffer = GlobalAlloc(GMEM_FIXED,
                            *lpcchSize * sizeof(WCHAR));
     if (lpBuffer == NULL)
@@ -707,6 +714,12 @@ GetProfilesDirectoryW(LPWSTR lpProfilesDir,
     HKEY hKey;
     LONG Error;
 
+    if (!lpcchSize)
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
+
     Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
                           L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
                           0,
@@ -774,6 +787,12 @@ GetUserProfileDirectoryA(HANDLE hToken,
     LPWSTR lpBuffer;
     BOOL bResult;
 
+    if (!lpProfileDir || !lpcchSize)
+    {
+        SetLastError( ERROR_INVALID_PARAMETER );
+        return FALSE;
+    }
+
     lpBuffer = GlobalAlloc(GMEM_FIXED,
                            *lpcchSize * sizeof(WCHAR));
     if (lpBuffer == NULL)
@@ -814,6 +833,12 @@ GetUserProfileDirectoryW(HANDLE hToken,
     HKEY hKey;
     LONG Error;
 
+    if (!lpcchSize)
+    {
+        SetLastError( ERROR_INVALID_PARAMETER );
+        return FALSE;
+    }
+
     if (!GetUserSidStringFromToken(hToken,
                                    &SidString))
     {