Unified · Split
| @@ -0,0 +1,4 @@ | ||
| 1 | +target | |
| 2 | +corpus | |
| 3 | +artifacts | |
| 4 | +coverage | |
| @@ -0,0 +1,28 @@ | ||
| 1 | +[package] | |
| 2 | +name = "gix-config-value-fuzz" | |
| 3 | +version = "0.0.0" | |
| 4 | +publish = false | |
| 5 | +edition = "2021" | |
| 6 | + | |
| 7 | +[package.metadata] | |
| 8 | +cargo-fuzz = true | |
| 9 | + | |
| 10 | +[dependencies] | |
| 11 | +libfuzzer-sys = "0.4" | |
| 12 | +gix-config-value = { path = ".." } | |
| 13 | +anyhow = "1.0.78" | |
| 14 | +bstr = "1.9.0" | |
| 15 | +arbitrary = { version = "1.3.2", features = ["derive"] } | |
| 16 | + | |
| 17 | +# Prevent this from interfering with workspaces | |
| 18 | +[workspace] | |
| 19 | +members = ["."] | |
| 20 | + | |
| 21 | +[profile.release] | |
| 22 | +debug = 1 | |
| 23 | + | |
| 24 | +[[bin]] | |
| 25 | +name = "fuzz_value" | |
| 26 | +path = "fuzz_targets/fuzz_value.rs" | |
| 27 | +test = false | |
| 28 | +doc = false | |
| @@ -0,0 +1,36 @@ | ||
| 1 | +# Names | |
| 2 | +"normal" | |
| 3 | +"default" | |
| 4 | +"black" | |
| 5 | +"brightblack" | |
| 6 | +"red" | |
| 7 | +"brightred" | |
| 8 | +"green" | |
| 9 | +"brightgreen" | |
| 10 | +"yellow" | |
| 11 | +"brightyellow" | |
| 12 | +"blue" | |
| 13 | +"brightblue" | |
| 14 | +"magenta" | |
| 15 | +"brightmagenta" | |
| 16 | +"cyan" | |
| 17 | +"brightcyan" | |
| 18 | +"white" | |
| 19 | +"brightwhite" | |
| 20 | + | |
| 21 | +# Attributes | |
| 22 | +"reset" | |
| 23 | +"bold" | |
| 24 | +"nobold" | |
| 25 | +"dim" | |
| 26 | +"nodim" | |
| 27 | +"ul" | |
| 28 | +"noul" | |
| 29 | +"blink" | |
| 30 | +"noblink" | |
| 31 | +"reverse" | |
| 32 | +"noreverse" | |
| 33 | +"italic" | |
| 34 | +"noitalic" | |
| 35 | +"strike" | |
| 36 | +"nostrike" | |
| @@ -0,0 +1,53 @@ | ||
| 1 | +#![no_main] | |
| 2 | + | |
| 3 | +extern crate libfuzzer_sys; | |
| 4 | + | |
| 5 | +use anyhow::Result; | |
| 6 | +use arbitrary::Arbitrary; | |
| 7 | +use bstr::BStr; | |
| 8 | +use gix_config_value::{ | |
| 9 | + color::{Attribute, Name}, | |
| 10 | + path::interpolate::Context, | |
| 11 | + Boolean, Color, Integer, Path, | |
| 12 | +}; | |
| 13 | +use libfuzzer_sys::fuzz_target; | |
| 14 | +use std::{borrow::Cow, fmt::Write, hint::black_box, str::FromStr}; | |
| 15 | + | |
| 16 | +#[derive(Debug, Arbitrary)] | |
| 17 | +struct Ctx<'a> { | |
| 18 | + bool_str: &'a [u8], | |
| 19 | + color_str: &'a [u8], | |
| 20 | + integer_str: &'a [u8], | |
| 21 | + path_str: &'a [u8], | |
| 22 | + attribute_str: &'a str, | |
| 23 | + name_str: &'a str, | |
| 24 | +} | |
| 25 | + | |
| 26 | +fn fuzz(ctx: Ctx) -> Result<()> { | |
| 27 | + let b = Boolean::try_from(BStr::new(ctx.bool_str))?; | |
| 28 | + _ = black_box(b.is_true()); | |
| 29 | + | |
| 30 | + _ = black_box(Color::try_from(BStr::new(ctx.color_str)))?; | |
| 31 | + | |
| 32 | + let mut buf = String::with_capacity(128); | |
| 33 | + let a = Attribute::from_str(ctx.attribute_str)?; | |
| 34 | + _ = black_box(write!(&mut buf, "{a}")); | |
| 35 | + | |
| 36 | + let name = Name::from_str(ctx.name_str)?; | |
| 37 | + _ = black_box(write!(&mut buf, "{name}")); | |
| 38 | + | |
| 39 | + let i = Integer::try_from(BStr::new(ctx.integer_str))?; | |
| 40 | + _ = black_box(i.to_decimal()); | |
| 41 | + | |
| 42 | + let p = Path::from(Cow::Borrowed(BStr::new(ctx.path_str))); | |
| 43 | + _ = black_box(p.interpolate(Context::default())); | |
| 44 | + | |
| 45 | + Ok(()) | |
| 46 | +} | |
| 47 | + | |
| 48 | +fuzz_target!(|ctx: Ctx| { | |
| 49 | + if let Err(e) = fuzz(ctx) { | |
| 50 | + // Excersize display/debug fmt code. | |
| 51 | + _ = black_box(format!("{e} {e:?}")); | |
| 52 | + } | |
| 53 | +}); | |
| @@ -204,7 +204,7 @@ impl FromStr for Name { · 203 unmodified lines | ||
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | if let Some(s) = s.strip_prefix('#') { |
| 207 | − if s.len() == 6 { | |
| 207 | + if s.len() == 6 && s.is_char_boundary(2) && s.is_char_boundary(4) && s.is_char_boundary(6) { | |
| 208 | 208 | let rgb = ( |
| 209 | 209 | u8::from_str_radix(&s[..2], 16), |
| 210 | 210 | u8::from_str_radix(&s[2..4], 16), |
| @@ -54,6 +54,7 @@ mod name { · 53 unmodified lines | ||
| 54 | 54 | assert!(Name::from_str("#").is_err()); |
| 55 | 55 | assert!(Name::from_str("#fff").is_err()); |
| 56 | 56 | assert!(Name::from_str("#gggggg").is_err()); |
| 57 | + assert!(Name::from_str("#=»©=").is_err()); | |
| 57 | 58 | } |
| 58 | 59 | } |
| 59 | 60 | |