From 4c6194facdcb1738681769a5e968582c6135cb7d Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 2 Apr 2024 22:54:53 +0200 Subject: [PATCH 1/2] fuzz the seq parse number functions --- fuzz/Cargo.toml | 6 ++++++ fuzz/fuzz_targets/fuzz_seq_parse_number.rs | 15 +++++++++++++++ src/uu/seq/src/seq.rs | 4 ++++ 3 files changed, 25 insertions(+) create mode 100644 fuzz/fuzz_targets/fuzz_seq_parse_number.rs diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index a97054192f1..e8ce7b697ce 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -92,6 +92,12 @@ path = "fuzz_targets/fuzz_test.rs" test = false doc = false +[[bin]] +name = "fuzz_seq_parse_number" +path = "fuzz_targets/fuzz_seq_parse_number.rs" +test = false +doc = false + [[bin]] name = "fuzz_parse_glob" path = "fuzz_targets/fuzz_parse_glob.rs" diff --git a/fuzz/fuzz_targets/fuzz_seq_parse_number.rs b/fuzz/fuzz_targets/fuzz_seq_parse_number.rs new file mode 100644 index 00000000000..04da6d47f99 --- /dev/null +++ b/fuzz/fuzz_targets/fuzz_seq_parse_number.rs @@ -0,0 +1,15 @@ +// This file is part of the uutils coreutils package. +// +// For the full copyright and license information, please view the LICENSE +// file that was distributed with this source code. +#![no_main] + +use libfuzzer_sys::fuzz_target; +use std::str::FromStr; +use uu_seq::number::PreciseNumber; + +fuzz_target!(|data: &[u8]| { + if let Ok(s) = std::str::from_utf8(data) { + let _ = PreciseNumber::from_str(s); + } +}); diff --git a/src/uu/seq/src/seq.rs b/src/uu/seq/src/seq.rs index 33b7636edbc..96ae83ba0a6 100644 --- a/src/uu/seq/src/seq.rs +++ b/src/uu/seq/src/seq.rs @@ -14,6 +14,10 @@ use uucore::{format_usage, help_about, help_usage}; mod error; mod extendedbigdecimal; +// public to allow fuzzing +#[cfg(fuzzing)] +pub mod number; +#[cfg(not(fuzzing))] mod number; mod numberparse; use crate::error::SeqError; From cd0a4d2fb6c9f12b11f34c8cd40508d34da8577b Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 2 Apr 2024 22:56:54 +0200 Subject: [PATCH 2/2] run fuzz_parse_number into the CI --- .github/workflows/fuzzing.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/fuzzing.yml b/.github/workflows/fuzzing.yml index e045d9b4f04..df40b123679 100644 --- a/.github/workflows/fuzzing.yml +++ b/.github/workflows/fuzzing.yml @@ -58,6 +58,8 @@ jobs: - { name: fuzz_parse_glob, should_pass: true } - { name: fuzz_parse_size, should_pass: true } - { name: fuzz_parse_time, should_pass: true } + - { name: fuzz_seq_parse_number, should_pass: true } + steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@nightly