[KERNEL32]
[reactos.git] / reactos / dll / win32 / kernel32 / client / path.c
index dd0c4f6..dc3b044 100644 (file)
@@ -210,9 +210,13 @@ BasepComputeProcessPath(IN PBASE_SEARCH_PATH_TYPE PathOrder,
             }
             else
             {
-                /* Add the length of the PATH variable */
+                /* Add the length of the PATH variable unless it's empty */
                 ASSERT(!(EnvPath.Length & 1));
-                PathLengthInBytes += (EnvPath.Length + sizeof(L';'));
+                if (EnvPath.Length)
+                {
+                    /* Reserve space for the variable and a semicolon */
+                    PathLengthInBytes += (EnvPath.Length + sizeof(L';'));
+                }
             }
             break;
 
@@ -2116,13 +2120,18 @@ GetTempPathW(IN DWORD count,
 
     ret++; /* add space for terminating 0 */
 
-    if (count)
+    if (count >= ret)
     {
         lstrcpynW(path, full_tmp_path, count);
-        if (count >= ret)
-            ret--; /* return length without 0 */
-        else if (count < 4)
-            path[0] = 0; /* avoid returning ambiguous "X:" */
+        /* the remaining buffer must be zeroed up to 32766 bytes in XP or 32767
+         * bytes after it, we will assume the > XP behavior for now */
+        memset(path + ret, 0, (min(count, 32767) - ret) * sizeof(WCHAR));
+        ret--; /* return length without 0 */
+    }
+    else if (count)
+    {
+        /* the buffer must be cleared if contents will not fit */
+        memset(path, 0, count * sizeof(WCHAR));
     }
 
     DPRINT("GetTempPathW returning %u, %S\n", ret, path);