mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-20 19:42:54 +02:00
Fix and improve win32 path validation.
llvm-svn: 19545
This commit is contained in:
parent
4e90250e81
commit
7dfbb46f7f
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user