https://git.reactos.org/?p=reactos.git;a=commitdiff;h=30f2ad79498910848aacdf2b03de88372f21556e

commit 30f2ad79498910848aacdf2b03de88372f21556e
Author:     Jérôme Gardou <[email protected]>
AuthorDate: Mon May 17 17:40:26 2021 +0200
Commit:     Jérôme Gardou <[email protected]>
CommitDate: Wed May 19 22:50:29 2021 +0200

    [RTL] Properly truncate 8dot3 names when using a MultiByte OEM code page
    
    CORE-17571
---
 sdk/lib/rtl/dos8dot3.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/sdk/lib/rtl/dos8dot3.c b/sdk/lib/rtl/dos8dot3.c
index 05301fd444f..1f9ead5e832 100644
--- a/sdk/lib/rtl/dos8dot3.c
+++ b/sdk/lib/rtl/dos8dot3.c
@@ -102,8 +102,9 @@ RtlGenerate8dot3Name(IN PUNICODE_STRING Name,
                 DotPos = Index;
         }
 
-        /* Copy name (6 valid characters max) */
-        for (Index = 0; Index < DotPos && Context->NameLength < 6; Index++)
+        /* Copy name. OEM string length can't exceed 6. */
+        UCHAR OemSizeLeft = 6;
+        for (Index = 0; (Index < DotPos) && OemSizeLeft; Index++)
         {
             Char = Name->Buffer[Index];
 
@@ -115,8 +116,17 @@ RtlGenerate8dot3Name(IN PUNICODE_STRING Name,
                 else if (Char >= L'a' && Char <= L'z')
                     Char = RtlpUpcaseUnicodeChar(Char);
 
+                /* Beware of MB OEM codepage */
+                if (NlsMbOemCodePageTag && 
HIBYTE(NlsUnicodeToMbOemTable[Char]))
+                {
+                    if (OemSizeLeft < 2)
+                        break;
+                    OemSizeLeft--;
+                }
+
                 Context->NameBuffer[Context->NameLength] = Char;
-                ++Context->NameLength;
+                Context->NameLength++;
+                OemSizeLeft--;
             }
         }
 

Reply via email to