Skip to content

Commit

Permalink
fix a stack overflow in the expression parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Geal committed Aug 17, 2021
1 parent 8b453bd commit 4851471
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions fuzz/fuzz_targets/fuzz_arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use nom::{
bytes::complete::tag,
character::complete::char,
character::complete::{digit1 as digit, space0 as space},
combinator::{map_res, verify},
combinator::{map, map_res, verify},
multi::fold_many0,
sequence::{delimited, pair},
sequence::{delimited, pair, terminated},
IResult,
};

Expand Down Expand Up @@ -48,7 +48,11 @@ fn decr() {
}

fn parens(i: &str) -> IResult<&str, i64> {
delimited(space, delimited(tag("("), expr, tag(")")), space)(i)
delimited(space, delimited(
terminated(tag("("), incr),
expr,
map(tag(")"), |_| decr())
), space)(i)
}


Expand Down

0 comments on commit 4851471

Please sign in to comment.