Guest User

Untitled

a guest
Jun 20th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. string Resolve(string fileName)
  2. {
  3. string root = FileRoot();
  4. string ret = Path.GetFullPath(Path.Combine(root, fileName));
  5. if (ret.StartsWith(root.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar)) return ret;
  6. throw new ArgumentException("path resolved to out of accesable directroy");
  7. }
  8.  
  9. public Boolean IsPathSafe(String rootPath, String relativePath)
  10. {
  11. return rootPath.EndsWith(Path.DirectorySeparatorChar.ToString()) &&
  12. Path.IsPathRooted(rootPath) &&
  13. Patch.Combine(rootPath, relativePath).GetFullPath().StartsWith(rootPath);
  14. }
Add Comment
Please, Sign In to add comment