refactor(core/rust): use FatPtr in rust syslog binding
What changed, and why it matters
This commit is a small internal cleanup in the Rust code that handles device logging. It replaces manual pointer-and-length handling with a helper called FatPtr, which is designed to safely represent string slices. There is no indication this change fixes a security bug or introduces a new vulnerability; it appears to be a routine refactoring that relies on a newly available language feature.
No security action required. Treat as normal code-review item; verify FatPtr correctly handles zero-length slices and preserves the previous non-null/length contract if the C side requires it.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff refactors core/embed/sys/src/syslog.rs to use rtl::util::FatPtr for converting Rust &str slices into C-style pointer/length pairs passed to syslog FFI functions. It removes a hand-written log_source_t::new constructor in favor of a From<&str> implementation, and uses FatPtr::from(text) for syslog_write_chunk. The change is syntactic and does not alter the underlying FFI signatures, trust boundaries, or data flow.
Changed components
core/embed/sys/src/syslog.rsInspect captured patch +12 / −15
diff --git a/core/embed/sys/src/syslog.rs b/core/embed/sys/src/syslog.rs
index 1ca5908b..db057f89 100644
--- a/core/embed/sys/src/syslog.rs
+++ b/core/embed/sys/src/syslog.rs
@@ -1,3 +1,5 @@
+use rtl::util::FatPtr;
+
use super::ffi;
#[derive(PartialEq, Debug, Eq, Clone, Copy)]
@@ -8,29 +10,24 @@ pub enum LogLevel {
Error = ffi::log_level_t_LOG_LEVEL_ERR as _,
}
-impl ffi::log_source_t {
- fn new(module: &str) -> Self {
- Self {
- name: module.as_ptr() as *const cty::c_char,
- name_len: module.len(),
+impl From<&str> for ffi::log_source_t {
+ fn from(s: &str) -> Self {
+ let ptr = FatPtr::from(s);
+ ffi::log_source_t {
+ name: ptr.ptr(),
+ name_len: ptr.len(),
}
}
}
fn syslog_start_record(module: &str, level: LogLevel) -> bool {
- let syslog_info = ffi::log_source_t::new(module);
- unsafe {
- ffi::syslog_start_record(
- &syslog_info as *const ffi::log_source_t,
- level as ffi::log_level_t,
- )
- }
+ let syslog_info = module.into();
+ unsafe { ffi::syslog_start_record(&syslog_info, level as ffi::log_level_t) }
}
fn syslog_write_chunk(text: &str, end_record: bool) -> Result<usize, ()> {
- let bytes_written = unsafe {
- ffi::syslog_write_chunk(text.as_ptr() as *const cty::c_char, text.len(), end_record)
- };
+ let text = FatPtr::from(text);
+ let bytes_written = unsafe { ffi::syslog_write_chunk(text.ptr(), text.len(), end_record) };
if bytes_written < 0 {
Err(())
} else {
Why this scored 12/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.