bitbox02/ui: inline confirm params in ui confirm
What changed, and why it matters
This commit is a small internal cleanup in the BitBox02 firmware's user-interface code. It moves the conversion of on-screen confirmation parameters from a helper method into the main confirmation function, removing an intermediate 'Survive' lifetime wrapper and scratch vectors. There is no indication this change fixes or introduces a security vulnerability.
No security action required. Treat as a normal refactoring review; verify that the lifetime/pointer safety of `c_params` relative to `title`/`body` is maintained, which it appears to be.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch inlines ConfirmParams::to_c_params() into ui::confirm(). Previously, to_c_params() accepted mutable title_scratch/body_scratch vectors and returned a Survive<'a, confirm_params_t> that tied the C struct’s lifetime to those vectors. The new code creates local title and body C-string vectors, builds confirm_params_t directly, and passes &c_params to confirm_create(). The local vectors remain in scope until after the unsafe C call, so the pointer validity is preserved. The change is behaviorally equivalent and reduces complexity.
Changed components
src/rust/bitbox02/src/ui/types.rssrc/rust/bitbox02/src/ui/ui.rsInspect captured patch +21 / −37
diff --git a/src/rust/bitbox02/src/ui/types.rs b/src/rust/bitbox02/src/ui/types.rs
index a2f8c2d..6a16367 100644
--- a/src/rust/bitbox02/src/ui/types.rs
+++ b/src/rust/bitbox02/src/ui/types.rs
@@ -52,38 +52,6 @@ pub struct ConfirmParams<'a> {
pub display_size: usize,
}
-impl<'a> ConfirmParams<'a> {
- #[cfg_attr(any(feature = "testing", feature = "c-unit-testing"), allow(dead_code))]
- /// `title_scratch` and `body_scratch` exist to keep the data
- /// alive for as long as the C params live.
- pub(crate) fn to_c_params(
- &self,
- title_scatch: &'a mut Vec<core::ffi::c_char>,
- body_scratch: &'a mut Vec<core::ffi::c_char>,
- ) -> Survive<'a, bitbox02_sys::confirm_params_t> {
- // We truncate at a bit higher than MAX_LABEL_SIZE, so the label component will correctly
- // truncate and append '...'.
- const TRUNCATE_SIZE: usize = MAX_LABEL_SIZE + 1;
- *title_scatch =
- util::strings::str_to_cstr_vec(util::strings::truncate_str(self.title, TRUNCATE_SIZE))
- .unwrap();
- *body_scratch =
- util::strings::str_to_cstr_vec(util::strings::truncate_str(self.body, TRUNCATE_SIZE))
- .unwrap();
- Survive::new(bitbox02_sys::confirm_params_t {
- title: title_scatch.as_ptr().cast(),
- title_autowrap: self.title_autowrap,
- body: body_scratch.as_ptr().cast(),
- font: self.font.as_ptr(),
- scrollable: self.scrollable,
- longtouch: self.longtouch,
- accept_only: self.accept_only,
- accept_is_nextarrow: self.accept_is_nextarrow,
- display_size: self.display_size as _,
- })
- }
-}
-
#[derive(Default)]
pub struct TrinaryInputStringParams<'a> {
/// The confirmation title of the screen. Max 200 chars, otherwise **panic**.
diff --git a/src/rust/bitbox02/src/ui/ui.rs b/src/rust/bitbox02/src/ui/ui.rs
index 70ab1fb..02e9203 100644
--- a/src/rust/bitbox02/src/ui/ui.rs
+++ b/src/rust/bitbox02/src/ui/ui.rs
@@ -139,13 +139,29 @@ pub async fn confirm(params: &ConfirmParams<'_>) -> bool {
}
}
- let mut title_scratch = Vec::new();
- let mut body_scratch = Vec::new();
+ // We truncate at a bit higher than MAX_LABEL_SIZE, so the label component will correctly
+ // truncate and append '...'.
+ const TRUNCATE_SIZE: usize = bitbox02_sys::MAX_LABEL_SIZE as usize + 1;
+ let title =
+ util::strings::str_to_cstr_vec(util::strings::truncate_str(params.title, TRUNCATE_SIZE))
+ .unwrap();
+ let body =
+ util::strings::str_to_cstr_vec(util::strings::truncate_str(params.body, TRUNCATE_SIZE))
+ .unwrap();
+ let c_params = bitbox02_sys::confirm_params_t {
+ title: title.as_ptr().cast(),
+ title_autowrap: params.title_autowrap,
+ body: body.as_ptr().cast(),
+ font: params.font.as_ptr(),
+ scrollable: params.scrollable,
+ longtouch: params.longtouch,
+ accept_only: params.accept_only,
+ accept_is_nextarrow: params.accept_is_nextarrow,
+ display_size: params.display_size as _,
+ };
let component = unsafe {
bitbox02_sys::confirm_create(
- ¶ms
- .to_c_params(&mut title_scratch, &mut body_scratch)
- .data,
+ &c_params,
Some(callback),
shared_state_ptr, // passed to callback as `user_data`.
)
Why this scored 11/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.