From: Jeff Cohen Date: Fri, 14 Jan 2005 04:09:39 +0000 (+0000) Subject: Fix and improve win32 path validation. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=3bbbcc113b4ff3bb5769d10c7e452cefcf812510;p=oota-llvm.git Fix and improve win32 path validation. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19545 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/System/Win32/Path.inc b/lib/System/Win32/Path.inc index a8862380e9e..7f891f43f9f 100644 --- a/lib/System/Win32/Path.inc +++ b/lib/System/Win32/Path.inc @@ -55,17 +55,29 @@ Path::isValid() const { != std::string::npos) return false; - // A file or directory name may not end in a period. - if (path[len-1] == '.') - return false; - if (len >= 2 && path[len-2] == '.' && path[len-1] == '/') - return false; + // Check each component for legality. + for (pos = 0; pos < len; ++pos) { + // A component may not end in a space. + if (path[pos] == ' ') { + if (path[pos+1] == '/' || path[pos+1] == '\0') + return false; + } - // A file or directory name may not end in a space. - if (path[len-1] == ' ') - return false; - if (len >= 2 && path[len-2] == ' ' && path[len-1] == '/') - return false; + // A component may not end in a period. + if (path[pos] == '.') { + if (path[pos+1] == '/' || path[pos+1] == '\0') { + // Unless it is the pseudo-directory "."... + if (pos == 0 || path[pos-1] == '/' || path[pos-1] == ':') + return true; + // or "..". + if (pos > 0 && path[pos-1] == '.') { + if (pos == 1 || path[pos-2] == '/' || path[pos-2] == ':') + return true; + } + return false; + } + } + } return true; }