Quentin JEROME 2 년 전
부모
커밋
d031ce78bf
1개의 변경된 파일6개의 추가작업 그리고 4개의 파일을 삭제
  1. 6 4
      bpf/aya-bpf/src/helpers.rs

+ 6 - 4
bpf/aya-bpf/src/helpers.rs

@@ -419,7 +419,7 @@ pub unsafe fn bpf_probe_read_user_str_bytes(
         dest.len() as u32,
         src as *const c_void,
     );
-    if len < 0 {
+    if len <= 0 {
         return Err(-1);
     }
 
@@ -430,7 +430,8 @@ pub unsafe fn bpf_probe_read_user_str_bytes(
         return Err(-1);
     }
 
-    Ok(&dest[..len])
+    // len includes NULL byte
+    Ok(&dest[..len - 1])
 }
 
 /// Read a null-terminated string from _kernel space_ stored at `src` into `dest`.
@@ -571,7 +572,7 @@ pub unsafe fn bpf_probe_read_kernel_str_bytes(
         dest.len() as u32,
         src as *const c_void,
     );
-    if len < 0 {
+    if len <= 0 {
         return Err(-1);
     }
 
@@ -582,7 +583,8 @@ pub unsafe fn bpf_probe_read_kernel_str_bytes(
         return Err(-1);
     }
 
-    Ok(&dest[..len])
+    // len includes NULL byte
+    Ok(&dest[..len - 1])
 }
 
 /// Write bytes to the _user space_ pointer `src` and store them as a `T`.