Add bounds checking for apob_read#2484
Conversation
|
Digging into whether this is practically reproducable to verify the fix was effective:
|
| // closure for performing the actual apob read | ||
| let fill = |buf: &mut [u8]| { | ||
| // Did the user pass in a reasonable size? | ||
| let Some(rbuf) = buf.get_mut(..size) else { |
There was a problem hiding this comment.
Do you prefer let/else to ok_or here?
There was a problem hiding this comment.
tbh I have a slight/weak preference to let-else here, but some of that is baseless preference, and some of that is habit because the .into() of ? can sometimes codegen slightly larger. That being said, I probably wouldn't refactor ok_or if I saw it.
| // the error types | ||
| ringbuf_entry!(Trace::ApobReadError { offset, err }); | ||
| let read_err = match err { | ||
| ApobReadError::NotImplemented => ApobReadResult::NotImplemented, |
There was a problem hiding this comment.
You may not know the answer to this either, since you just moved this code, but...why are these types distinct?
There was a problem hiding this comment.
use drv_hf_api::ApobReadError;
use host_sp_messages::ApobReadResult;I think they are just different types from different sources, IPC vs IPCC types? I think there are probably just two different wire schemas we're marshalling between here, not 100% certain though.
Currently WIP, waiting to validate on real hardware before marking this ready for merge.