Browse Source

aya: Do not use unwrap with btf_fd in bpf_create_map

Fixes a crash when trying to create a map of type BPF_MAP_TYPE_PERCPU_ARRAY when btf_fd is None.

Tested on Ubuntu 18.04 (4.15.0-202-generic)
Mary 1 year ago
parent
commit
7c25fe90a9
1 changed files with 1 additions and 1 deletions
  1. 1 1
      aya/src/sys/bpf.rs

+ 1 - 1
aya/src/sys/bpf.rs

@@ -66,7 +66,7 @@ pub(crate) fn bpf_create_map(name: &CStr, def: &obj::Map, btf_fd: Option<RawFd>)
             _ => {
                 u.btf_key_type_id = m.def.btf_key_type_id;
                 u.btf_value_type_id = m.def.btf_value_type_id;
-                u.btf_fd = btf_fd.unwrap() as u32;
+                u.btf_fd = btf_fd.unwrap_or_default() as u32;
             }
         }
     }