Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uplink: Fix passing dangling stack pointer #91

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions uplink/src/edge/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,17 @@ impl Config {
access: &access::Grant,
opts: Option<&OptionsRegisterAccess>,
) -> Result<credentials::Gateway> {
let uc_opts = if let Some(o) = opts {
&o.as_ffi_options_register_access() as *const ulksys::EdgeRegisterAccessOptions
} else {
ptr::null()
};
// N.B.: Be sure to bind the options to a variable that lives long enough to be passed to
// the FFI.
let mut uc_opts = opts.map(|o| o.as_ffi_options_register_access());
let uc_opts_ptr = uc_opts.as_mut().map_or(ptr::null_mut(), |o| {
o as *mut ulksys::EdgeRegisterAccessOptions
});

// SAFETY: we trust the FFI is safe creating an instance of its own types and rely in our
// implemented FFI methods to return valid FFI values with correct lifetimes.
let uc_res = unsafe {
ulksys::edge_register_access(
self.inner,
access.as_ffi_access(),
uc_opts as *mut ulksys::EdgeRegisterAccessOptions,
)
ulksys::edge_register_access(self.inner, access.as_ffi_access(), uc_opts_ptr)
};

credentials::Gateway::from_ffi_credentials_result(uc_res)
Expand Down
Loading