Skip to content

Commit d30344d

Browse files
committed
multiboot2: fix warning and miri error
1 parent 3178ccb commit d30344d

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

multiboot2/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- **Breaking:** Removed the optional `unstable` feature (required nightly)
66
- `core::error::Error` is now implemented unconditionally
77
- **Breaking:** The MSRV is now 1.81
8+
- Fixed a bug causing UB in `ElfSection::name()`
89

910
## v0.23.1 (2024-10-21)
1011

multiboot2/src/elf_sections.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,19 @@ impl ElfSection<'_> {
320320
}
321321

322322
unsafe fn string_table(&self) -> *const u8 {
323-
let addr = match self.entry_size {
324-
40 => (*(self.string_section as *const ElfSectionInner32)).addr as usize,
325-
64 => (*(self.string_section as *const ElfSectionInner64)).addr as usize,
323+
match self.entry_size {
324+
40 => {
325+
let ptr = self.string_section.cast::<ElfSectionInner32>();
326+
let reference = unsafe { ptr.as_ref().unwrap() };
327+
reference.addr() as *const u8
328+
}
329+
64 => {
330+
let ptr = self.string_section.cast::<ElfSectionInner64>();
331+
let reference = unsafe { ptr.as_ref().unwrap() };
332+
reference.addr() as *const u8
333+
}
326334
s => panic!("Unexpected entry size: {}", s),
327-
};
328-
addr as *const _
335+
}
329336
}
330337
}
331338

0 commit comments

Comments
 (0)