Skip to content

Commit 9836592

Browse files
committed
Rust: Fix compilation errors in example code.
1 parent 7b1aa23 commit 9836592

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

rust/ql/src/queries/security/CWE-117/LogInjectionBad.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ use log::info;
33

44
fn main() {
55
env_logger::init();
6-
6+
77
// Get username from command line arguments
88
let args: Vec<String> = env::args().collect();
9-
let username = args.get(1).unwrap_or(&String::from("Guest"));
10-
9+
let username = args.get(1).unwrap_or(&String::from("Guest")).clone();
10+
1111
// BAD: log message constructed with unsanitized user input
1212
info!("User login attempt: {}", username);
13-
}
13+
}

rust/ql/src/queries/security/CWE-117/LogInjectionGood.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ fn sanitize_for_logging(input: &str) -> String {
88

99
fn main() {
1010
env_logger::init();
11-
11+
1212
// Get username from command line arguments
1313
let args: Vec<String> = env::args().collect();
14-
let username = args.get(1).unwrap_or(&String::from("Guest"));
15-
14+
let username = args.get(1).unwrap_or(&String::from("Guest")).clone();
15+
1616
// GOOD: log message constructed with sanitized user input
17-
let sanitized_username = sanitize_for_logging(username);
17+
let sanitized_username = sanitize_for_logging(username.as_str());
1818
info!("User login attempt: {}", sanitized_username);
19-
}
19+
}

0 commit comments

Comments
 (0)