Fix #5603: Prefer absolute path for /drive: syntax.
authorArmin Novak <armin.novak@thincast.com>
Tue, 24 Sep 2019 13:44:34 +0000 (15:44 +0200)
committerArmin Novak <armin.novak@thincast.com>
Tue, 24 Sep 2019 14:42:27 +0000 (16:42 +0200)
client/common/cmdline.c
winpr/include/winpr/path.h
winpr/libwinpr/path/shell.c

index 8487f97..c23c4d5 100644 (file)
@@ -103,9 +103,12 @@ static BOOL freerdp_client_add_drive(rdpSettings* settings, const char* path, co
                /* Path was entered as secondary argument, swap */
                if (PathFileExistsA(name))
                {
-                       const char* tmp = path;
-                       path = name;
-                       name = tmp;
+                       if (!PathFileExistsA(path) || (!PathIsRelativeA(name) && PathIsRelativeA(path)))
+                       {
+                               const char* tmp = path;
+                               path = name;
+                               name = tmp;
+                       }
                }
        }
 
index 8f9a9d0..ed52b1c 100644 (file)
@@ -288,6 +288,9 @@ WINPR_API BOOL PathMakePathA(LPCSTR path, LPSECURITY_ATTRIBUTES lpAttributes);
 
 #if !defined(_WIN32) || defined(_UWP)
 
+WINPR_API BOOL PathIsRelativeA(LPCSTR pszPath);
+WINPR_API BOOL PathIsRelativeW(LPCWSTR pszPath);
+
 WINPR_API BOOL PathFileExistsA(LPCSTR pszPath);
 WINPR_API BOOL PathFileExistsW(LPCWSTR pszPath);
 
index 95e16dd..513b817 100644 (file)
@@ -521,6 +521,27 @@ BOOL PathMakePathA(LPCSTR path, LPSECURITY_ATTRIBUTES lpAttributes)
 
 #if !defined(_WIN32) || defined(_UWP)
 
+BOOL PathIsRelativeA(LPCSTR pszPath)
+{
+       if (!pszPath)
+               return FALSE;
+
+       return pszPath[0] != '/';
+}
+
+BOOL PathIsRelativeW(LPCWSTR pszPath)
+{
+       LPSTR lpFileNameA = NULL;
+       BOOL ret;
+
+       if (ConvertFromUnicode(CP_UTF8, 0, pszPath, -1, &lpFileNameA, 0, NULL, NULL) < 1)
+               return FALSE;
+
+       ret = PathIsRelativeA(lpFileNameA);
+       free(lpFileNameA);
+       return ret;
+}
+
 BOOL PathFileExistsA(LPCSTR pszPath)
 {
        struct stat stat_info;