Don't panic on bad nonce_size#2584
Merged
Merged
Conversation
jamesmunns
approved these changes
Jul 2, 2026
jamesmunns
left a comment
Contributor
There was a problem hiding this comment.
This LGTM, modulo one tiny style nit and one "made me look".
| // Ensure the requester didn't send a bad nonce_size that's | ||
| // larger than the actual blob. | ||
| let nonce_size = nonce_size as usize; | ||
| if nonce_size > req.blob.len() { |
Contributor
There was a problem hiding this comment.
Tiny nit, I usually prefer something like:
let Some(nonce) = req.blob.get(..nonce_size) else {
return Err(SprotError::Protocol(
SprotProtocolError::BadMessageLength,
));
};
Ok((
RspBody::Attest(Ok(AttestRsp::Attest)),
Some(TrailingData::Attest { nonce, write_size }),
))which lets you do the "length check" and "subslice" in one step.
Collaborator
There was a problem hiding this comment.
I have also begun to find joy in let / else
Contributor
Author
There was a problem hiding this comment.
Yeah that's nicer!
| /// Unknown message | ||
| BadMessageType, | ||
| /// Transfer size is outside of maximum and minimum lenghts for message type. | ||
| /// Transfer size is outside of maximum and minimum lengths for message |
Contributor
There was a problem hiding this comment.
I did go and check, we do check that the nonce is a valid size elsewhere (I think min and max are checked in different places?).
labbott
approved these changes
Jul 2, 2026
| // Ensure the requester didn't send a bad nonce_size that's | ||
| // larger than the actual blob. | ||
| let nonce_size = nonce_size as usize; | ||
| if nonce_size > req.blob.len() { |
Collaborator
There was a problem hiding this comment.
I have also begun to find joy in let / else
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before, the SP could cause the RoT to panic by sending it an
attestrequest with anonce_sizelarger than the actual blob of nonce data. Now the RoT replies with aBadMessageLengtherror instead.This is slightly different than the other uses of
BadMessageLength, but I don't think it's worth making a new error variant just for this case and plumbing it through MGS. Tell me if you disagree.Tested on a grapefruit.