From b4eabfd0a1eaca783c6a0fe35de8b1166412f078 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Wed, 3 Jun 2015 01:37:34 +0200
Subject: server: When combining root and name, make sure there is only one
 slash. (v2)

Changes in v2:
  * Resolve inter-patch conflict.
---
 dlls/ntdll/tests/file.c |  4 ++--
 server/fd.c             | 16 ++++++++++++----
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/dlls/ntdll/tests/file.c b/dlls/ntdll/tests/file.c
index 440cfaa..40c932b 100644
--- a/dlls/ntdll/tests/file.c
+++ b/dlls/ntdll/tests/file.c
@@ -2111,8 +2111,8 @@ static void test_file_rename_information(void)
     res = pNtQueryInformationFile( handle, &io, fni, sizeof(FILE_NAME_INFORMATION) + MAX_PATH * sizeof(WCHAR), FileNameInformation );
     ok( res == STATUS_SUCCESS, "res expected STATUS_SUCCESS, got %x\n", res );
     fni->FileName[ fni->FileNameLength / sizeof(WCHAR) ] = 0;
-    todo_wine ok( !lstrcmpW(fni->FileName, newpath + 2), "FileName expected %s, got %s\n",
-                  wine_dbgstr_w(newpath + 2), wine_dbgstr_w(fni->FileName) );
+    ok( !lstrcmpW(fni->FileName, newpath + 2), "FileName expected %s, got %s\n",
+        wine_dbgstr_w(newpath + 2), wine_dbgstr_w(fni->FileName) );
     HeapFree( GetProcessHeap(), 0, fni );
 
     CloseHandle( handle );
diff --git a/server/fd.c b/server/fd.c
index b30ae11..07e0fc5 100644
--- a/server/fd.c
+++ b/server/fd.c
@@ -1720,6 +1720,7 @@ void set_fd_user( struct fd *fd, const struct fd_ops *user_ops, struct object *u
 char *dup_fd_name( struct fd *root, const char *name )
 {
     char *ret;
+    int len;
 
     if (!root) return strdup( name );
     if (!root->unix_name) return NULL;
@@ -1727,11 +1728,18 @@ char *dup_fd_name( struct fd *root, const char *name )
     /* skip . prefix */
     if (name[0] == '.' && (!name[1] || name[1] == '/')) name++;
 
-    if ((ret = malloc( strlen(root->unix_name) + strlen(name) + 2 )))
+    len = strlen( root->unix_name );
+    if ((ret = malloc( len + strlen(name) + 2 )))
     {
-        strcpy( ret, root->unix_name );
-        if (name[0] && name[0] != '/') strcat( ret, "/" );
-        strcat( ret, name );
+        memcpy( ret, root->unix_name, len );
+        while (len && ret[len - 1] == '/') len--;
+        while (name[0] == '/') name++;
+        if (name[0])
+        {
+            ret[ len ] = '/';
+            strcpy( ret + len + 1, name );
+        }
+        else ret[ len ] = 0;
     }
     return ret;
 }
-- 
2.5.0

