Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fuzz the expr command #4642

Merged
merged 1 commit into from
Sep 26, 2023
Merged

Fuzz the expr command #4642

merged 1 commit into from
Sep 26, 2023

Conversation

sylvestre
Copy link
Contributor

Based on:
#4641

@@ -149,6 +149,13 @@ jobs:
## Run it
cd fuzz
cargo +nightly fuzz run fuzz_test -- -max_total_time=${{ env.RUN_FOR }} -detect_leaks=0
- name: Run fuzz_expr for XX seconds
continue-on-error: true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for now, it is failing but we don't fail the job on it.
I opened :
#5315
#5316

but we probably have more issues

@sylvestre
Copy link
Contributor Author

sylvestre commented Sep 24, 2023

as expected, fails quickly:

Expression: 60 + 60 | 9 < 38pkYJ * 45ÃhgÃ0 | 96 - 78 & 71
Rust code: 2
GNU code: 0
thread '<unnamed>' panicked at fuzz_targets/fuzz_expr.rs:167:17:
Different error codes

Comment on lines +44 to +65
fn generate_random_string(max_length: usize) -> String {
let mut rng = rand::thread_rng();
let valid_utf8: Vec<char> = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
.chars()
.collect();
let invalid_utf8 = [0xC3, 0x28]; // Invalid UTF-8 sequence
let mut result = String::new();

for _ in 0..rng.gen_range(1..=max_length) {
if rng.gen_bool(0.9) {
let ch = valid_utf8.choose(&mut rng).unwrap();
result.push(*ch);
} else {
let ch = invalid_utf8.choose(&mut rng).unwrap();
if let Some(c) = char::from_u32(*ch as u32) {
result.push(c);
}
}
}

result
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function looks like a candidate for fuzz_common.rs as it is used in fuzz_test.rs, too.

.to_string()
.trim()
.to_owned();

Copy link
Contributor

@cakebaker cakebaker Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 111 - 156 also look like a candidate for fuzz_common.rs, they seem to be identical to the code in fuzz_test.rs.

Copy link
Contributor

@cakebaker cakebaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good :) My suggestions are probably more something for a future PR.

@sylvestre
Copy link
Contributor Author

agreed, it was part of my place to refactor some of the code :)

@sylvestre sylvestre merged commit e0a4143 into uutils:main Sep 26, 2023
44 of 45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants