From 6320253c9456007c10659a85de41f437b129a8f6 Mon Sep 17 00:00:00 2001 From: Jeffrey Morlan Date: Sat, 26 Jul 2008 17:15:37 +0000 Subject: [PATCH] In mkdir, don't add a backslash to the end - it can trick CreateDirectory into creating a dir with the name of a DOS device (even in Windows). svn path=/trunk/; revision=34810 --- reactos/base/shell/cmd/internal.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/reactos/base/shell/cmd/internal.c b/reactos/base/shell/cmd/internal.c index 8771b3ef399..4dac60911a4 100644 --- a/reactos/base/shell/cmd/internal.c +++ b/reactos/base/shell/cmd/internal.c @@ -439,16 +439,16 @@ MakeFullPath(TCHAR * DirPath) p += 2; while (*p == _T('\\')) p++; /* skip drive root */ - while ((p = _tcschr(p, _T('\\'))) != NULL) + do { - n = p - DirPath + 1; + p = _tcschr(p, _T('\\')); + n = p ? p++ - DirPath : _tcslen(DirPath); _tcsncpy(path, DirPath, n); path[n] = _T('\0'); if( !CreateDirectory(path, NULL) && (GetLastError() != ERROR_ALREADY_EXISTS)) return FALSE; - p++; - } + } while (p != NULL); if (GetLastError() == ERROR_ALREADY_EXISTS) SetLastError(ERROR_SUCCESS); @@ -463,7 +463,7 @@ INT cmd_mkdir (LPTSTR cmd, LPTSTR param) { LPTSTR dir; /* pointer to the directory to change to */ LPTSTR place; /* used to search for the \ when no space is used */ - LPTSTR new_dir, *p = NULL; + LPTSTR *p = NULL; INT argc; nErrorLevel = 0; if (!_tcsncmp (param, _T("/?"), 2)) @@ -516,17 +516,6 @@ INT cmd_mkdir (LPTSTR cmd, LPTSTR param) return 1; } - /* Add a \ at the end of the path is there isnt on already */ - if (dir[_tcslen (dir) - 1] != _T('\\')) - { - new_dir = cmd_realloc(dir, (_tcslen (dir) + 2) * sizeof(TCHAR)); - if (new_dir != NULL) - { - p[0] = dir = new_dir; - _tcscat(dir,_T("\\")); - } - } - if (!MakeFullPath(dir)) { if(GetLastError() == ERROR_PATH_NOT_FOUND)