ZipCommon.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //
  2. // ZipCommon.cpp
  3. //
  4. // Library: Zip
  5. // Package: Zip
  6. // Module: ZipCommon
  7. //
  8. // Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
  9. // and Contributors.
  10. //
  11. // SPDX-License-Identifier: BSL-1.0
  12. //
  13. #include "Poco/Zip/ZipCommon.h"
  14. #include "Poco/Path.h"
  15. namespace Poco {
  16. namespace Zip {
  17. bool ZipCommon::isValidPath(const std::string& path)
  18. {
  19. try
  20. {
  21. if (Path(path, Path::PATH_UNIX).isAbsolute() || Path(path, Path::PATH_WINDOWS).isAbsolute())
  22. return false;
  23. }
  24. catch (...)
  25. {
  26. return false;
  27. }
  28. if (path == "..")
  29. return false;
  30. if ((path.size() >= 3) && path.compare(0, 3, "../") == 0)
  31. return false;
  32. if ((path.size() >= 3) && path.compare(0, 3, "..\\") == 0)
  33. return false;
  34. if (path.find("/../") != std::string::npos)
  35. return false;
  36. if (path.find("\\..\\") != std::string::npos)
  37. return false;
  38. if (path.find("/..\\") != std::string::npos)
  39. return false;
  40. if (path.find("\\../") != std::string::npos)
  41. return false;
  42. if ((path.size() >= 2) && path.compare(0, 2, "~/") == 0)
  43. return false;
  44. return true;
  45. }
  46. } } // namespace Poco::Zip