diff --git a/test/integration-ebpf/src/bpf_probe_read.rs b/test/integration-ebpf/src/bpf_probe_read.rs index 02728767..64d56311 100644 --- a/test/integration-ebpf/src/bpf_probe_read.rs +++ b/test/integration-ebpf/src/bpf_probe_read.rs @@ -15,11 +15,11 @@ macro_rules! read_str_bytes { let Some(ptr) = RESULT.get_ptr_mut(0) else { return; }; - let TestResult { - did_error, - len, - buf, - } = unsafe { &mut *ptr }; + let dst = unsafe { ptr.as_mut() }; + let Some(TestResult { buf, len }) = dst else { + return; + }; + *len = None; // $len comes from ctx.arg(1) so it's dynamic and the verifier // doesn't see any bounds. We do $len.min(RESULT_BUF_LEN) here to @@ -35,22 +35,14 @@ macro_rules! read_str_bytes { return; }; - match unsafe { $fun($ptr, buf) } { - Ok(s) => { - *len = s.len(); - } - Err(_) => { - *did_error = 1; - } - } + *len = Some(unsafe { $fun($ptr, buf) }.map(<[_]>::len)); }; } #[repr(C)] struct TestResult { - did_error: u64, - len: usize, buf: [u8; RESULT_BUF_LEN], + len: Option>, } #[map] diff --git a/test/integration-test/src/tests/bpf_probe_read.rs b/test/integration-test/src/tests/bpf_probe_read.rs index bf91f271..4c425507 100644 --- a/test/integration-test/src/tests/bpf_probe_read.rs +++ b/test/integration-test/src/tests/bpf_probe_read.rs @@ -5,9 +5,8 @@ const RESULT_BUF_LEN: usize = 1024; #[derive(Copy, Clone)] #[repr(C)] struct TestResult { - did_error: u64, - len: usize, buf: [u8; RESULT_BUF_LEN], + len: Option>, } unsafe impl aya::Pod for TestResult {} @@ -96,11 +95,12 @@ fn set_kernel_buffer_element(bpf: &mut Bpf, bytes: &[u8]) { #[track_caller] fn result_bytes(bpf: &Bpf) -> Vec { let m = Array::<_, TestResult>::try_from(bpf.map("RESULT").unwrap()).unwrap(); - let result = m.get(&0, 0).unwrap(); - assert_eq!(result.did_error, 0); + let TestResult { buf, len } = m.get(&0, 0).unwrap(); + let len = len.unwrap(); + let len = len.unwrap(); // assert that the buffer is always null terminated - assert_eq!(result.buf[result.len], 0); - result.buf[..result.len].to_vec() + assert_eq!(buf[len], 0); + buf[..len].to_vec() } fn load_and_attach_uprobe(prog_name: &str, func_name: &str, bytes: &[u8]) -> Bpf {