summaryrefslogtreecommitdiffstats
path: root/llvm/lib/System/Win32
diff options
context:
space:
mode:
authorJeff Cohen <jeffc@jolt-lang.org>2005-01-14 04:09:39 +0000
committerJeff Cohen <jeffc@jolt-lang.org>2005-01-14 04:09:39 +0000
commite246cdc9469963771456c64c80df35af9800cdca (patch)
tree46db66a02de79b19b798eecfbbec06098955fbac /llvm/lib/System/Win32
parentcbeed3571a052e91d80ea95ad94d52ddc736ae51 (diff)
downloadbcm5719-llvm-e246cdc9469963771456c64c80df35af9800cdca.tar.gz
bcm5719-llvm-e246cdc9469963771456c64c80df35af9800cdca.zip
Fix and improve win32 path validation.
llvm-svn: 19545
Diffstat (limited to 'llvm/lib/System/Win32')
-rw-r--r--llvm/lib/System/Win32/Path.inc32
1 files changed, 22 insertions, 10 deletions
diff --git a/llvm/lib/System/Win32/Path.inc b/llvm/lib/System/Win32/Path.inc
index a8862380e9e..7f891f43f9f 100644
--- a/llvm/lib/System/Win32/Path.inc
+++ b/llvm/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;
}
OpenPOWER on IntegriCloud