From cb8b26b4ba0660043c40093f99df4a5d5f5725fb Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 1 Mar 2014 13:51:02 +0200 Subject: [PATCH] Fix bug #16751 with crashes in expand-file-name on Windows. src/fileio.c (Fexpand_file_name) [WINDOWSNT]: Don't treat file names that start with more than 2 slashes as UNCs. --- src/ChangeLog | 5 +++++ src/fileio.c | 16 +++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 704ac68b67e..1f351e71403 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2014-03-01 Eli Zaretskii + + * fileio.c (Fexpand_file_name) [WINDOWSNT]: Don't treat file names + that start with more than 2 slashes as UNCs. (Bug#16751) + 2014-02-28 Paul Eggert Fix a few crashes and leaks when cloning C strings. diff --git a/src/fileio.c b/src/fileio.c index d03a2bcf02f..fb0a33b39db 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -1047,10 +1047,9 @@ filesystem tree, not (expand-file-name ".." dirname). */) nm++; /* Discard any previous drive specifier if nm is now in UNC format. */ - if (IS_DIRECTORY_SEP (nm[0]) && IS_DIRECTORY_SEP (nm[1])) - { - drive = 0; - } + if (IS_DIRECTORY_SEP (nm[0]) && IS_DIRECTORY_SEP (nm[1]) + && !IS_DIRECTORY_SEP (nm[2])) + drive = 0; #endif /* WINDOWSNT */ #endif /* DOS_NT */ @@ -1261,7 +1260,8 @@ filesystem tree, not (expand-file-name ".." dirname). */) && !IS_DIRECTORY_SEP (nm[0]) #endif #ifdef WINDOWSNT - && !(IS_DIRECTORY_SEP (nm[0]) && IS_DIRECTORY_SEP (nm[1])) + && !(IS_DIRECTORY_SEP (nm[0]) && IS_DIRECTORY_SEP (nm[1]) + && !IS_DIRECTORY_SEP (nm[2])) #endif && !newdir) { @@ -1286,7 +1286,8 @@ filesystem tree, not (expand-file-name ".." dirname). */) && IS_DEVICE_SEP (newdir[1]) && IS_DIRECTORY_SEP (newdir[2])) #ifdef WINDOWSNT /* Detect Windows file names in UNC format. */ - && ! (IS_DIRECTORY_SEP (newdir[0]) && IS_DIRECTORY_SEP (newdir[1])) + && ! (IS_DIRECTORY_SEP (newdir[0]) && IS_DIRECTORY_SEP (newdir[1]) + && !IS_DIRECTORY_SEP (newdir[2])) #endif ) { @@ -1346,7 +1347,8 @@ filesystem tree, not (expand-file-name ".." dirname). */) if (IS_DIRECTORY_SEP (nm[0]) && collapse_newdir) { #ifdef WINDOWSNT - if (IS_DIRECTORY_SEP (newdir[0]) && IS_DIRECTORY_SEP (newdir[1])) + if (IS_DIRECTORY_SEP (newdir[0]) && IS_DIRECTORY_SEP (newdir[1]) + && !IS_DIRECTORY_SEP (newdir[2])) { char *adir = strcpy (alloca (strlen (newdir) + 1), newdir); char *p = adir + 2; -- 2.39.2