mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
pv: BinReqValues: Fix length validation in get()
Return an error when the provided request data is smaller than the
expected request length. The previous condition used the wrong
comparison, which could lead to an out-of-bounds slice and panic.
Add a regression test.
Fixes: 34bef977e8 ("rust/pv: User-data signing and verifying")
Assisted-by: IBM Bob:1.0.5
Signed-off-by: Marc Hartmayer <marc@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
committed by
Jan Höppner
parent
187437c6c8
commit
a93146d976
@@ -79,7 +79,7 @@ impl<'a> BinReqValues<'a> {
|
||||
let rql = hdr.rql.get() as usize;
|
||||
let sea = hdr.sea.get() as usize;
|
||||
|
||||
if rql < req.len() || sea + Self::TAG_LEN > rql {
|
||||
if req.len() < rql || sea + Self::TAG_LEN > rql {
|
||||
return Err(Error::BinRequestSmall);
|
||||
}
|
||||
let aad_size = rql - sea - Self::TAG_LEN;
|
||||
@@ -262,4 +262,18 @@ mod tests {
|
||||
];
|
||||
assert_eq!(hdr_bin, &hdr_bin_exp);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bin_req_values_buffer_too_small() {
|
||||
// Create a valid header with request length set to 200 bytes
|
||||
let hdr = RequestHdr::new(0x200, 200, [0x11; 12], 1, 32, Some(TEST_MAGIC));
|
||||
let hdr_bin = hdr.as_bytes();
|
||||
|
||||
// Create a buffer that's smaller than the declared request length (48
|
||||
// bytes)
|
||||
let small_buffer = Vec::from(hdr_bin);
|
||||
|
||||
let result = BinReqValues::get(&small_buffer);
|
||||
assert!(matches!(result, Err(Error::BinRequestSmall)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user