Skip to content

Commit 3fcf8c2

Browse files
committed
fixer
1 parent 7115fb6 commit 3fcf8c2

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

libafl_qemu/src/modules/usermode/redirect_stdin.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const SYS_read: u8 = 63;
2424
/// You need to use this with snapshot module!
2525
#[derive(Debug, Default)]
2626
pub struct RedirectStdinModule {
27-
input_addr: GuestAddr,
27+
input_addr: Option<GuestAddr>,
2828
read: usize,
2929
total: usize,
3030
}
@@ -33,12 +33,12 @@ impl RedirectStdinModule {
3333
#[must_use]
3434
/// constuctor
3535
pub fn new() -> Self {
36-
Self::with_input_addr(0)
36+
Self::with_input_addr(None)
3737
}
3838

3939
#[must_use]
4040
/// Create with specified input address
41-
pub fn with_input_addr(addr: GuestAddr) -> Self {
41+
pub fn with_input_addr(addr: Option<GuestAddr>) -> Self {
4242
Self {
4343
input_addr: addr,
4444
read: 0,
@@ -47,7 +47,7 @@ impl RedirectStdinModule {
4747
}
4848

4949
/// Tell this module where to look for the input addr
50-
pub fn set_input_addr(&mut self, addr: GuestAddr) {
50+
pub fn set_input_addr(&mut self, addr: Option<GuestAddr>) {
5151
self.input_addr = addr;
5252
}
5353
}
@@ -57,8 +57,12 @@ where
5757
I: Unpin + HasLen + Debug,
5858
S: Unpin,
5959
{
60-
fn post_qemu_init<ET>(&mut self, _qemu: Qemu, emulator_modules: &mut EmulatorModules<ET, I, S>)
61-
where
60+
fn first_exec<ET>(
61+
&mut self,
62+
_qemu: Qemu,
63+
emulator_modules: &mut EmulatorModules<ET, I, S>,
64+
_state: &mut S,
65+
) where
6266
ET: EmulatorModuleTuple<I, S>,
6367
{
6468
emulator_modules.pre_syscalls(Hook::Function(syscall_read_hook::<ET, I, S>));
@@ -73,7 +77,7 @@ where
7377
) where
7478
ET: EmulatorModuleTuple<I, S>,
7579
{
76-
assert!(self.input_addr != 0);
80+
assert!(self.input_addr.is_some());
7781
self.total = input.len();
7882
self.read = 0;
7983
}
@@ -100,7 +104,10 @@ where
100104
S: Unpin,
101105
{
102106
let h = emulator_modules.get_mut::<RedirectStdinModule>().unwrap();
103-
107+
let addr = match h.input_addr {
108+
Some(addr) => addr,
109+
None => return SyscallHookResult::new(None),
110+
};
104111
if syscall == SYS_read as i32 && x0 == 0 {
105112
/*
106113
println!(
@@ -109,7 +116,7 @@ where
109116
);
110117
*/
111118
let size = unsafe {
112-
let mut src = h.input_addr as *const u8;
119+
let mut src = addr as *const u8;
113120
src = src.wrapping_add(h.read);
114121
let dst = x1 as *mut u8;
115122
if h.total >= h.read {

0 commit comments

Comments
 (0)