Jeff Smith : kernelbase: Fix PathAllocCanonicalize handling segments that contain dots.

Alexandre Julliard julliard at winehq.org
Mon Apr 20 15:01:47 CDT 2020


Module: wine
Branch: oldstable
Commit: 5278fb29acd7e9f89947ac600038e1a605a5df50
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=5278fb29acd7e9f89947ac600038e1a605a5df50

Author: Jeff Smith <whydoubt at gmail.com>
Date:   Thu Sep 19 12:04:30 2019 +0800

kernelbase: Fix PathAllocCanonicalize handling segments that contain dots.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=47766
Signed-off-by: Zhiyi Zhang <zzhang at codeweavers.com>
Signed-off-by: Jeff Smith <whydoubt at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
(cherry picked from commit c13a8f60bdef5b69f5db61f79efb7fd341a27303)
Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>

---

 dlls/kernelbase/path.c | 35 ++++++++++++++++++++---------------
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/dlls/kernelbase/path.c b/dlls/kernelbase/path.c
index bcd129cce9..adefe3abc7 100644
--- a/dlls/kernelbase/path.c
+++ b/dlls/kernelbase/path.c
@@ -204,13 +204,8 @@ HRESULT WINAPI PathAllocCanonicalize(const WCHAR *path_in, DWORD flags, WCHAR **
                     continue;
                 }
 
-                /* Keep the . if one of the following is true:
-                 * 1. PATHCCH_DO_NOT_NORMALIZE_SEGMENTS
-                 * 2. in form of a..b
-                 */
-                if (dst > buffer
-                    && (((flags & PATHCCH_DO_NOT_NORMALIZE_SEGMENTS) && dst[-1] != '\\')
-                        || (dst[-1] != '\\' && src[2] != '\\' && src[2])))
+                /* Keep the .. if not surrounded by \ */
+                if ((src[2] != '\\' && src[2]) || (dst > buffer && dst[-1] != '\\'))
                 {
                     *dst++ = *src++;
                     *dst++ = *src++;
@@ -241,14 +236,8 @@ HRESULT WINAPI PathAllocCanonicalize(const WCHAR *path_in, DWORD flags, WCHAR **
             }
             else
             {
-                /* Keep the . if one of the following is true:
-                 * 1. PATHCCH_DO_NOT_NORMALIZE_SEGMENTS
-                 * 2. in form of a.b, which is used in domain names
-                 * 3. *.
-                 */
-                if (dst > buffer
-                    && ((flags & PATHCCH_DO_NOT_NORMALIZE_SEGMENTS && dst[-1] != '\\')
-                        || (dst[-1] != '\\' && src[1] != '\\' && src[1]) || (dst[-1] == '*')))
+                /* Keep the . if not surrounded by \ */
+                if ((src[1] != '\\' && src[1]) || (dst > buffer && dst[-1] != '\\'))
                 {
                     *dst++ = *src++;
                     continue;
@@ -280,6 +269,22 @@ HRESULT WINAPI PathAllocCanonicalize(const WCHAR *path_in, DWORD flags, WCHAR **
     /* End the path */
     *dst = 0;
 
+    /* Strip multiple trailing . */
+    if (!(flags & PATHCCH_DO_NOT_NORMALIZE_SEGMENTS))
+    {
+        while (dst > buffer && dst[-1] == '.')
+        {
+            /* Keep a . after * */
+            if (dst - 1 > buffer && dst[-2] == '*')
+                break;
+            /* If . follow a : at the second character, remove the . and add a \ */
+            else if (dst - 1 > buffer && dst[-2] == ':' && dst - 2 == buffer + 1)
+                *--dst = '\\';
+            else
+                *--dst = 0;
+        }
+    }
+
     /* If result path is empty, fill in \ */
     if (!*buffer)
     {




More information about the wine-cvs mailing list