Bug 1400513 - u2f-hid-rs: fuzzers should use a deterministic cmd byte r=jcj

Summary: We're currently using the thread_rng to derive a cmd byte for the U2F protocol fuzzers. That of course should rather be derived deterministically from the input handed to the fuzzing target.

Bug #: 1400513

Differential Revision: https://phabricator.services.mozilla.com/D61
This commit is contained in:
Tim Taubert 2017-09-17 20:07:32 +02:00
parent efb7d369f2
commit cd9cddcc94
11 changed files with 13 additions and 11 deletions

View File

@ -4,10 +4,8 @@
#![no_main]
#[macro_use] extern crate libfuzzer_sys;
extern crate rand;
extern crate u2fhid;
use rand::{thread_rng, Rng};
use std::{cmp, io};
use u2fhid::{CID_BROADCAST, HID_RPT_SIZE};
@ -59,7 +57,10 @@ impl<'a> U2FDevice for TestDevice<'a> {
}
fuzz_target!(|data: &[u8]| {
let mut dev = TestDevice::new(data);
let cmd = thread_rng().gen::<u8>();
let _ = sendrecv(&mut dev, cmd, data);
if data.len() > 0 {
let cmd = data[0];
let data = &data[1..];
let mut dev = TestDevice::new(data);
let _ = sendrecv(&mut dev, cmd, data);
}
});

View File

@ -4,10 +4,8 @@
#![no_main]
#[macro_use] extern crate libfuzzer_sys;
extern crate rand;
extern crate u2fhid;
use rand::{thread_rng, Rng};
use std::{cmp, io};
use u2fhid::{CID_BROADCAST, HID_RPT_SIZE};
@ -60,8 +58,11 @@ impl U2FDevice for TestDevice {
}
fuzz_target!(|data: &[u8]| {
let mut dev = TestDevice::new();
let cmd = thread_rng().gen::<u8>();
let res = sendrecv(&mut dev, cmd, data);
assert_eq!(data, &res.unwrap()[..]);
if data.len() > 0 {
let cmd = data[0];
let data = &data[1..];
let mut dev = TestDevice::new();
let res = sendrecv(&mut dev, cmd, data);
assert_eq!(data, &res.unwrap()[..]);
}
});