Skip to content

Commit

Permalink
Fix code scanning alert deepmodeling#725: Uncontrolled data used in p…
Browse files Browse the repository at this point in the history
…ath expression

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: Jinzhe Zeng <[email protected]>
  • Loading branch information
njzjz and github-advanced-security[bot] authored Sep 18, 2024
1 parent ba9f02f commit bcd9a6a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions source/ipi/driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,25 @@ 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;
std::cerr << argv[0] << " input_script " << std::endl;
return 0;
}

if (!isValidPath(argv[1])) {
std::cerr << "Invalid file path." << std::endl;
return 1;
}

std::ifstream fp(argv[1]);
json jdata;
fp >> jdata;
Expand Down

0 comments on commit bcd9a6a

Please sign in to comment.