Author: hbelusca
Date: Fri Sep 13 22:27:41 2013
New Revision: 60085

URL: http://svn.reactos.org/svn/reactos?rev=60085&view=rev
Log:
[KERNEL32]
- npipe.c:
  * Use RtlPrefixUnicodeString instead of RtlPrefixString with casts.
  * Check results of RtlCreateUnicodeString and RtlPrefixUnicodeString, return 
FALSE if they fail and set an appropriate last error.
  * Free the string created with RtlCreateUnicodeString instead of leaking 
memory.
  * Fix a path type check (RtlPathTypeUncAbsolute instead of 
RtlPathTypeRootLocalDevice).
- path.c: I prefer seeing the default case at the end of the switch (no 
functional changes).

[NTOS:MM]
- Use RtlPrefixUnicodeString instead of RtlPrefixString with casts.

[RTL]
- RtlPrefixString acts on general PSTRINGs (which are not UNICODE).
- Remove extra spaces between names of functions and parentheses.
- Clarify the fact that we run over characters.

Modified:
    trunk/reactos/dll/win32/kernel32/client/file/npipe.c
    trunk/reactos/dll/win32/kernel32/client/path.c
    trunk/reactos/include/ndk/rtlfuncs.h
    trunk/reactos/lib/rtl/unicode.c
    trunk/reactos/ntoskrnl/mm/ARM3/sysldr.c

Modified: trunk/reactos/dll/win32/kernel32/client/file/npipe.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/file/npipe.c?rev=60085&r1=60084&r2=60085&view=diff
==============================================================================
--- trunk/reactos/dll/win32/kernel32/client/file/npipe.c        [iso-8859-1] 
(original)
+++ trunk/reactos/dll/win32/kernel32/client/file/npipe.c        [iso-8859-1] 
Fri Sep 13 22:27:41 2013
@@ -382,7 +382,11 @@
 
     /* Start by making a unicode string of the name */
     TRACE("Sent path: %S\n", lpNamedPipeName);
-    RtlCreateUnicodeString(&NamedPipeName, lpNamedPipeName);
+    if (!RtlCreateUnicodeString(&NamedPipeName, lpNamedPipeName))
+    {
+        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+        return FALSE;
+    }
     NameLength = NamedPipeName.Length / sizeof(WCHAR);
 
     /* All slashes must become backslashes */
@@ -401,7 +405,14 @@
     {
         /* Make sure it's a valid prefix */
         RtlInitUnicodeString(&PipePrefix, L"\\\\.\\pipe\\");
-        RtlPrefixString((PANSI_STRING)&PipePrefix, (PANSI_STRING)&NewName, 
TRUE);
+        if (!RtlPrefixUnicodeString(&PipePrefix, &NewName, TRUE))
+        {
+            /* The name is invalid */
+            WARN("Invalid name!\n");
+            RtlFreeUnicodeString(&NamedPipeName);
+            BaseSetLastNTError(STATUS_OBJECT_PATH_SYNTAX_BAD);
+            return FALSE;
+        }
 
         /* Move past it */
         NewName.Buffer += 9;
@@ -411,7 +422,7 @@
         TRACE("NewName: %wZ\n", &NewName);
         RtlInitUnicodeString(&DevicePath, L"\\DosDevices\\pipe\\");
     }
-    else if (Type == RtlPathTypeRootLocalDevice)
+    else if (Type == RtlPathTypeUncAbsolute)
     {
         /* The path is \\server\\pipe\name; find the pipename itself */
         p = &NewName.Buffer[2];
@@ -436,6 +447,7 @@
         {
             /* The name is invalid */
             WARN("Invalid name!\n");
+            RtlFreeUnicodeString(&NamedPipeName);
             BaseSetLastNTError(STATUS_OBJECT_PATH_SYNTAX_BAD);
             return FALSE;
         }
@@ -445,6 +457,7 @@
     else
     {
         WARN("Invalid path type\n");
+        RtlFreeUnicodeString(&NamedPipeName);
         BaseSetLastNTError(STATUS_OBJECT_PATH_SYNTAX_BAD);
         return FALSE;
     }
@@ -455,6 +468,7 @@
     WaitPipeInfo = RtlAllocateHeap(RtlGetProcessHeap(), 0, WaitPipeInfoSize);
     if (WaitPipeInfo == NULL)
     {
+        RtlFreeUnicodeString(&NamedPipeName);
         SetLastError(ERROR_NOT_ENOUGH_MEMORY);
         return FALSE;
     }
@@ -478,9 +492,9 @@
     {
         /* Fail; couldn't open */
         WARN("Status: %lx\n", Status);
+        RtlFreeHeap(RtlGetProcessHeap(), 0, WaitPipeInfo);
+        RtlFreeUnicodeString(&NamedPipeName);
         BaseSetLastNTError(Status);
-        RtlFreeUnicodeString(&NamedPipeName);
-        RtlFreeHeap(RtlGetProcessHeap(), 0, WaitPipeInfo);
         return FALSE;
     }
 
@@ -537,7 +551,7 @@
     {
         /* Failure to wait on the pipe */
         WARN("Status: %lx\n", Status);
-        BaseSetLastNTError (Status);
+        BaseSetLastNTError(Status);
         return FALSE;
      }
 

Modified: trunk/reactos/dll/win32/kernel32/client/path.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/path.c?rev=60085&r1=60084&r2=60085&view=diff
==============================================================================
--- trunk/reactos/dll/win32/kernel32/client/path.c      [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/client/path.c      [iso-8859-1] Fri Sep 13 
22:27:41 2013
@@ -740,25 +740,9 @@
     /* Check what kind of path this is and how many slashes to skip */
     switch (RtlDetermineDosPathNameType_U(Path))
     {
-        case RtlPathTypeDriveAbsolute:
-            return Path + 3;
-
-        case RtlPathTypeDriveRelative:
-            return Path + 2;
-
-        case RtlPathTypeRooted:
-            return Path + 1;
-
-        case RtlPathTypeRelative:
-            return Path;
-
-        case RtlPathTypeRootLocalDevice:
-        default:
-            return NULL;
-
         case RtlPathTypeUncAbsolute:
         case RtlPathTypeLocalDevice:
-
+        {
             /* Keep going until we bypass the path indicators */
             for (ReturnPath = Path + 2, i = 2; (i > 0) && (*ReturnPath); 
ReturnPath++)
             {
@@ -767,6 +751,23 @@
             }
 
             return ReturnPath;
+        }
+
+        case RtlPathTypeDriveAbsolute:
+            return Path + 3;
+
+        case RtlPathTypeDriveRelative:
+            return Path + 2;
+
+        case RtlPathTypeRooted:
+            return Path + 1;
+
+        case RtlPathTypeRelative:
+            return Path;
+
+        case RtlPathTypeRootLocalDevice:
+        default:
+            return NULL;
     }
 }
 

Modified: trunk/reactos/include/ndk/rtlfuncs.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/rtlfuncs.h?rev=60085&r1=60084&r2=60085&view=diff
==============================================================================
--- trunk/reactos/include/ndk/rtlfuncs.h        [iso-8859-1] (original)
+++ trunk/reactos/include/ndk/rtlfuncs.h        [iso-8859-1] Fri Sep 13 
22:27:41 2013
@@ -2165,8 +2165,8 @@
 BOOLEAN
 NTAPI
 RtlPrefixString(
-    PCANSI_STRING String1,
-    PCANSI_STRING String2,
+    PSTRING String1,
+    PSTRING String2,
     BOOLEAN CaseInsensitive
 );
 

Modified: trunk/reactos/lib/rtl/unicode.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/unicode.c?rev=60085&r1=60084&r2=60085&view=diff
==============================================================================
--- trunk/reactos/lib/rtl/unicode.c     [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/unicode.c     [iso-8859-1] Fri Sep 13 22:27:41 2013
@@ -835,17 +835,18 @@
 BOOLEAN
 NTAPI
 RtlPrefixString(
-    PANSI_STRING String1,
-    PANSI_STRING String2,
-    BOOLEAN  CaseInsensitive)
+    PSTRING String1,
+    PSTRING String2,
+    BOOLEAN CaseInsensitive)
 {
     PCHAR pc1;
     PCHAR pc2;
-    ULONG Length;
-
-    if (String2->Length < String1->Length) return FALSE;
-
-    Length = String1->Length;
+    ULONG NumChars;
+
+    if (String2->Length < String1->Length)
+        return FALSE;
+
+    NumChars = String1->Length;
     pc1 = String1->Buffer;
     pc2 = String2->Buffer;
 
@@ -853,15 +854,15 @@
     {
         if (CaseInsensitive)
         {
-            while (Length--)
+            while (NumChars--)
             {
-                if (RtlUpperChar (*pc1++) != RtlUpperChar (*pc2++))
+                if (RtlUpperChar(*pc1++) != RtlUpperChar(*pc2++))
                     return FALSE;
             }
         }
         else
         {
-            while (Length--)
+            while (NumChars--)
             {
                 if (*pc1++ != *pc2++)
                     return FALSE;
@@ -889,7 +890,7 @@
 {
     PWCHAR pc1;
     PWCHAR pc2;
-    ULONG NumChars;
+    ULONG  NumChars;
 
     if (String2->Length < String1->Length)
         return FALSE;
@@ -923,6 +924,7 @@
 
     return FALSE;
 }
+
 /*
  * @implemented
  */

Modified: trunk/reactos/ntoskrnl/mm/ARM3/sysldr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/sysldr.c?rev=60085&r1=60084&r2=60085&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/mm/ARM3/sysldr.c     [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/ARM3/sysldr.c     [iso-8859-1] Fri Sep 13 
22:27:41 2013
@@ -827,9 +827,9 @@
                                              InLoadOrderLinks);
 
                 /* Check if it matches */
-                if (RtlPrefixString((PSTRING)&ForwarderName,
-                                    (PSTRING)&LdrEntry->BaseDllName,
-                                    TRUE))
+                if (RtlPrefixUnicodeString(&ForwarderName,
+                                           &LdrEntry->BaseDllName,
+                                           TRUE))
                 {
                     /* Get the forwarder export directory */
                     ForwardExportDirectory =


Reply via email to