[NTOSKRNL] Unify buffer size calculation in FsRtlIs{Name,Dbcs}InExpression
authorBartosz Brachaczek <b.brachaczek@gmail.com>
Sun, 31 Mar 2019 23:58:21 +0000 (01:58 +0200)
committerPierre Schweitzer <pierre@reactos.org>
Mon, 1 Apr 2019 06:27:59 +0000 (08:27 +0200)
It better captures the intent now in FsRtlIsNameInExpressionPrivate and
fixes a slight overallotion by 4 bytes in FsRtlIsDbcsInExpression.

While at it, use the ANSI_DOS_DOT macro in the Dbcs version.

CORE-15902

ntoskrnl/fsrtl/dbcsname.c
ntoskrnl/fsrtl/name.c

index 2c7300f..3b1afd8 100644 (file)
@@ -291,7 +291,7 @@ FsRtlIsDbcsInExpression(IN PANSI_STRING Expression,
                     ASSERT((OldBackTracking == BackTrackingBuffer) || (OldBackTracking == OldBackTrackingBuffer));
 
                     /* Calculate buffer size */
-                    BackTrackingBufferSize = (Expression->Length + 1) * 2;
+                    BackTrackingBufferSize = Expression->Length * 2 + 1;
 
                     /* Allocate memory for both back-tracking buffers */
                     AllocatedBuffer = ExAllocatePoolWithTag(PagedPool | POOL_RAISE_IF_ALLOCATION_FAILURE,
@@ -386,7 +386,7 @@ FsRtlIsDbcsInExpression(IN PANSI_STRING Expression,
                     continue;
                 }
                 /* Check DOS_DOT */
-                else if (ExpressionChar == DOS_DOT)
+                else if (ExpressionChar == ANSI_DOS_DOT)
                 {
                     if (EndOfName) continue;
 
index ef760c3..3d2b33e 100644 (file)
@@ -143,7 +143,7 @@ FsRtlIsNameInExpressionPrivate(IN PUNICODE_STRING Expression,
                     ASSERT((OldBackTracking == BackTrackingBuffer) || (OldBackTracking == OldBackTrackingBuffer));
 
                     /* Calculate buffer size */
-                    BackTrackingBufferSize = Expression->Length + 1;
+                    BackTrackingBufferSize = Expression->Length / sizeof(WCHAR) * 2 + 1;
 
                     /* Allocate memory for both back-tracking buffers */
                     AllocatedBuffer = ExAllocatePoolWithTag(PagedPool | POOL_RAISE_IF_ALLOCATION_FAILURE,