diff --git a/source/ipi/driver.cc b/source/ipi/driver.cc index 9a91a27ad3..76f93f798e 100644 --- a/source/ipi/driver.cc +++ b/source/ipi/driver.cc @@ -48,6 +48,13 @@ char *trimwhitespace(char *str) { return str; } +bool isValidPath(const std::string &path) { + if (path.find("..") != std::string::npos || path.find('/') != std::string::npos || path.find('\\') != std::string::npos) { + return false; + } + return true; +} + int main(int argc, char *argv[]) { if (argc == 1) { std::cerr << "usage " << std::endl; @@ -55,6 +62,11 @@ int main(int argc, char *argv[]) { return 0; } + if (!isValidPath(argv[1])) { + std::cerr << "Invalid file path." << std::endl; + return 1; + } + std::ifstream fp(argv[1]); json jdata; fp >> jdata;