-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #101: disallow lookahead within lookbehind in Ruby
- Loading branch information
Showing
15 changed files
with
136 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
tmin input: | ||
cargo afl tmin -i {{input}} -o out.txt -- ./target/debug/afl-fuzz | ||
AFL_DEBUG=1 AFL_MAP_SIZE=100000 cargo afl tmin -i {{input}} -o out.txt -- ./target/debug/afl-fuzz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use std::ops::{Deref, DerefMut}; | ||
|
||
pub(crate) struct Deferred<'a, S, F: FnMut(&mut S)> { | ||
state: &'a mut S, | ||
mutate: F, | ||
} | ||
|
||
impl<'a, S, F: FnMut(&mut S)> Deferred<'a, S, F> { | ||
pub(crate) fn new(state: &'a mut S, mutate: F) -> Self { | ||
Deferred { state, mutate } | ||
} | ||
} | ||
|
||
impl<'a, S, F: FnMut(&mut S)> Drop for Deferred<'a, S, F> { | ||
fn drop(&mut self) { | ||
let mutator = &mut self.mutate; | ||
mutator(self.state); | ||
} | ||
} | ||
|
||
impl<'a, S, F: FnMut(&mut S)> Deref for Deferred<'a, S, F> { | ||
type Target = S; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.state | ||
Check warning on line 25 in pomsky-lib/src/defer.rs GitHub Actions / clippythis expression creates a reference which is immediately dereferenced by the compiler
|
||
} | ||
} | ||
|
||
impl<'a, S, F: FnMut(&mut S)> DerefMut for Deferred<'a, S, F> { | ||
fn deref_mut(&mut self) -> &mut Self::Target { | ||
&mut self.state | ||
Check warning on line 31 in pomsky-lib/src/defer.rs GitHub Actions / clippythis expression creates a reference which is immediately dereferenced by the compiler
|
||
} | ||
} | ||
|
||
#[doc(hidden)] | ||
pub(crate) trait Mutable { | ||
fn mutable(&mut self) -> &mut Self; | ||
} | ||
|
||
impl<T> Mutable for T { | ||
fn mutable(&mut self) -> &mut Self { | ||
self | ||
} | ||
} | ||
|
||
macro_rules! revert_on_drop { | ||
($state:ident . $($id:tt).*) => { | ||
let __prev = $state.$($id).*; | ||
let mut $state = { | ||
use $crate::defer::Mutable as _; | ||
$crate::defer::Deferred::new($state.mutable(), move |$state| { | ||
$state.$($id).* = __prev; | ||
}) | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,9 @@ | |
|
||
#![warn(missing_docs)] | ||
|
||
#[macro_use] | ||
mod defer; | ||
|
||
pub mod diagnose; | ||
pub mod error; | ||
pub mod features; | ||
|
4 changes: 4 additions & 0 deletions
4
pomsky-lib/tests/testcases/boundaries/ruby_word_boundary_in_lookbehind.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#! flavor=Ruby | ||
>> % | ||
----- | ||
(?=\b) |
4 changes: 4 additions & 0 deletions
4
pomsky-lib/tests/testcases/boundaries/ruby_word_start_in_lookahead.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#! flavor=Ruby | ||
>> < | ||
----- | ||
(?=(?<!\w)(?=\w)) |
5 changes: 5 additions & 0 deletions
5
pomsky-lib/tests/testcases/boundaries/ruby_word_start_in_lookbehind.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#! expect=error, flavor=Ruby | ||
<< < | ||
----- | ||
ERROR: In the Ruby flavor, `<` and `>` word boundaries are not allowed within lookbehind | ||
SPAN: 3..4 |
4 changes: 4 additions & 0 deletions
4
pomsky-lib/tests/testcases/lookaround/ruby_lookahead_after_lookbehind.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#! flavor=Ruby | ||
(<< 'foo') (>> 'bar') | ||
----- | ||
(?<=foo)(?=bar) |
5 changes: 5 additions & 0 deletions
5
pomsky-lib/tests/testcases/lookaround/ruby_lookahead_in_lookbehind_1.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#! expect=error, flavor=Ruby | ||
<< 'foo' >> 'bar' | ||
----- | ||
ERROR: In the Ruby flavor, lookahead is not allowed within lookbehind | ||
SPAN: 9..17 |
6 changes: 6 additions & 0 deletions
6
pomsky-lib/tests/testcases/lookaround/ruby_lookahead_in_lookbehind_2.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#! expect=error, flavor=Ruby | ||
let la = >> 'bar'; | ||
<< 'foo' la | ||
----- | ||
ERROR: In the Ruby flavor, lookahead is not allowed within lookbehind | ||
SPAN: 9..17 |