Skip to content

Commit 2daef7e

Browse files
committed
Rust: remove use of home_dir from test
1 parent 80bdd81 commit 2daef7e

File tree

1 file changed

+3
-3
lines changed
  • rust/ql/test/query-tests/security/CWE-022/src

1 file changed

+3
-3
lines changed

rust/ql/test/query-tests/security/CWE-022/src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn tainted_path_handler_good(Query(file_name): Query<String>) -> Result<String>
2222

2323
//#[handler]
2424
fn tainted_path_handler_folder_good(Query(file_path): Query<String>) -> Result<String> {
25-
let public_path = home_dir().unwrap().join("public");
25+
let public_path = PathBuf::from("/var/www/public_html");
2626
let file_path = public_path.join(PathBuf::from(file_path));
2727
let file_path = file_path.canonicalize().unwrap();
2828
// GOOD: ensure that the path stays within the public folder
@@ -36,7 +36,7 @@ fn tainted_path_handler_folder_good(Query(file_path): Query<String>) -> Result<S
3636
fn tainted_path_handler_folder_almost_good1(
3737
Query(file_path): Query<String>, // $ Source=remote4
3838
) -> Result<String> {
39-
let public_path = home_dir().unwrap().join("public");
39+
let public_path = PathBuf::from("/var/www/public_html");
4040
let file_path = public_path.join(PathBuf::from(file_path));
4141
// BAD: the path could still contain `..` and escape the public folder
4242
if !file_path.starts_with(public_path) {
@@ -49,7 +49,7 @@ fn tainted_path_handler_folder_almost_good1(
4949
fn tainted_path_handler_folder_almost_good2(
5050
Query(file_path): Query<String>, // $ Source=remote5
5151
) -> Result<String> {
52-
let public_path = home_dir().unwrap().join("public");
52+
let public_path = PathBuf::from("/var/www/public_html");
5353
let file_path = public_path.join(PathBuf::from(file_path));
5454
let file_path = file_path.canonicalize().unwrap();
5555
// BAD: thecheck to ensure that the path stays within the public folder is wrong

0 commit comments

Comments
 (0)