Skip to content

Commit b12ecbf

Browse files
committed
multiboot2: module.rs: add more sanity checks
1 parent 8012fa9 commit b12ecbf

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

multiboot2/Changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- **BREAKING** Fixed wrong creation of `EFIMemoryMapTag`.
77
`EFIMemoryMapTag::new` was replaced by `EFIMemoryMapTag::new_from_descs` and
88
`EFIMemoryMapTag::new_from_map`.
9+
- `ModuleTag::new`'s `end` parameter now must be bigger than `start`.
910

1011
## 0.20.0 (2024-05-01)
1112

multiboot2/src/module.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ pub struct ModuleTag {
2626
impl ModuleTag {
2727
#[cfg(feature = "builder")]
2828
pub fn new(start: u32, end: u32, cmdline: &str) -> BoxedDst<Self> {
29+
assert!(end > start, "must have a size");
30+
2931
let mut cmdline_bytes: Vec<_> = cmdline.bytes().collect();
3032
if !cmdline_bytes.ends_with(&[0]) {
3133
// terminating null-byte
@@ -135,7 +137,7 @@ mod tests {
135137
&((TagType::Module.val()).to_le_bytes()),
136138
&size.to_le_bytes(),
137139
&0_u32.to_le_bytes(),
138-
&0_u32.to_le_bytes(),
140+
&1_u32.to_le_bytes(),
139141
MSG.as_bytes(),
140142
// Null Byte
141143
&[0],
@@ -161,15 +163,15 @@ mod tests {
161163
#[test]
162164
#[cfg(feature = "builder")]
163165
fn test_build_str() {
164-
let tag = ModuleTag::new(0, 0, MSG);
166+
let tag = ModuleTag::new(0, 1, MSG);
165167
let bytes = tag.as_bytes();
166168
assert_eq!(bytes, get_bytes());
167169
assert_eq!(tag.cmdline(), Ok(MSG));
168170

169171
// test also some bigger message
170-
let tag = ModuleTag::new(0, 0, "AbCdEfGhUjK YEAH");
172+
let tag = ModuleTag::new(0, 1, "AbCdEfGhUjK YEAH");
171173
assert_eq!(tag.cmdline(), Ok("AbCdEfGhUjK YEAH"));
172-
let tag = ModuleTag::new(0, 0, "AbCdEfGhUjK YEAH".repeat(42).as_str());
174+
let tag = ModuleTag::new(0, 1, "AbCdEfGhUjK YEAH".repeat(42).as_str());
173175
assert_eq!(tag.cmdline(), Ok("AbCdEfGhUjK YEAH".repeat(42).as_str()));
174176
}
175177
}

0 commit comments

Comments
 (0)