Skip to content

Commit d576c23

Browse files
andreeaflorescuSamuel Ortiz
authored and
Samuel Ortiz
committed
added regression test for underflow error
While loading an invalid bzimage the linux loader could crash because of underflow. This tests is a regression test for the bug fix. Signed-off-by: Andreea Florescu <[email protected]>
1 parent 6bdbb2b commit d576c23

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

coverage_config_x86_64.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"coverage_score": 80.0,
2+
"coverage_score": 81.0,
33
"exclude_path": "",
44
"crate_features": "bzimage,elf",
55
"exclude_path": "benches/,loader_gen/"
559 Bytes
Binary file not shown.

src/loader/x86_64/bzimage/mod.rs

+28
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,32 @@ mod tests {
270270
.err()
271271
);
272272
}
273+
274+
#[test]
275+
fn test_invalid_bzimage_underflow() {
276+
use super::super::super::Error as LoaderError;
277+
278+
let path = concat!(
279+
env!("CARGO_MANIFEST_DIR"),
280+
"/src/loader/x86_64/bzimage/invalid_bzimage.bin"
281+
);
282+
283+
let gm = create_guest_mem();
284+
let mut image = File::open(path).unwrap();
285+
let kernel_offset = GuestAddress(0x200000);
286+
let highmem_start_address = GuestAddress(0x0);
287+
288+
// load bzImage with good kernel_offset and himem_start setting
289+
let loader_result = BzImage::load(
290+
&gm,
291+
Some(kernel_offset),
292+
&mut image,
293+
Some(highmem_start_address),
294+
);
295+
296+
assert_eq!(
297+
loader_result.unwrap_err(),
298+
LoaderError::Bzimage(Error::Underflow)
299+
);
300+
}
273301
}

0 commit comments

Comments
 (0)