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

Consider different API for 'handle' utilities #91

Open
frewsxcv opened this issue Sep 19, 2016 · 1 comment
Open

Consider different API for 'handle' utilities #91

frewsxcv opened this issue Sep 19, 2016 · 1 comment

Comments

@frewsxcv
Copy link
Member

frewsxcv commented Sep 19, 2016

#46 added some utilities to handle stdin and panics. Here's a different design I was thinking about:

struct Input(io::Stdin);

impl Input {
    pub fn into_bytes() -> Vec<u8> {
        unimplemented!()
    }

    pub fn into_string() -> Option<String> {
        let mut input = String::new();
        let result = io::stdin().read_to_string(&mut input);
        match result {
            Ok(_) => Some(input),
            Err(_) => None,
        }
    }
}

impl Read for Input {
    ...
}

pub fn handle<F>(closure: F)
    where F: FnOnce(Input) + UnwindSafe
{
    let input = Input(io::stdin());
    let result = panic::catch_unwind(|| {
        closure(input);
    });
    if result.is_err() {
        unsafe {
            abort();
        }
    }
}

instead of handle_* functions, just one handle function with one input type: Input. The downsides of this design though is that a user might want a string and to input.into_string().unwrap() which will cause a panic sometimes which will result in a crash for AFL.

@alex
Copy link
Member

alex commented Sep 19, 2016

There are existing APIs for creating an io::Read or a String from
&[u8], any reason not to just let people use those?

On Sun, Sep 18, 2016 at 9:53 PM, Corey Farwell [email protected]
wrote:

#46 #46 added some utilities to
handle stdin and panics. Here's a different design I was thinking about:

struct Input(io::Stdin);
impl Input {
pub fn into_bytes() -> Vec {

}

pub fn into_string() -> Option<String> {
    let mut input = String::new();
    let result = io::stdin().read_to_string(&mut input);
    match result {
        Ok(_) => Some(input),
        Err(_) => None,
    }
}

}
pub fn new_handle(closure: F)
where F: FnOnce(Input) + UnwindSafe
{
let input = Input(io::stdin());
let result = panic::catch_unwind(|| {
closure(input);
});
if result.is_err() {
// TODO: add option to prevent this abort?
unsafe {
abort();
}
}
}

instead of handle_* functions, just one handle function with one input
type: Input. The downsides of this design though is that a user might
want a string and to input.into_string().unwrap() which will cause a
panic sometimes which will result in a crash for AFL.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#91, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAADBJ9WWuGLyqzcjC8islWk15Iwi6V8ks5qresEgaJpZM4KAFTl
.

"I disapprove of what you say, but I will defend to the death your right to
say it." -- Evelyn Beatrice Hall (summarizing Voltaire)
"The people's good is the highest law." -- Cicero
GPG Key fingerprint: D1B3 ADC0 E023 8CA6

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

No branches or pull requests

2 participants