Skip to content

Commit d529fa3

Browse files
Remove access to unaligned refs from bzImage tests
Replace access to unaligned reference in bzImage tests with std::ptr::addr_of macro and `read_unaligned` method. Signed-off-by: Alexandru Cihodaru <[email protected]>
1 parent e1dccdd commit d529fa3

File tree

1 file changed

+18
-5
lines changed
  • src/loader/x86_64/bzimage

1 file changed

+18
-5
lines changed

src/loader/x86_64/bzimage/mod.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ mod tests {
221221
v
222222
}
223223

224-
#[allow(unaligned_references)]
225224
#[allow(non_snake_case)]
226225
#[test]
227226
fn test_load_bzImage() {
@@ -238,10 +237,19 @@ mod tests {
238237
Some(highmem_start_address),
239238
)
240239
.unwrap();
240+
let setup_header = loader_result.setup_header.unwrap();
241241

242242
assert_eq!(loader_result.kernel_load.raw_value(), 0x200000);
243-
assert_eq!(loader_result.setup_header.unwrap().header, 0x53726448);
244-
assert_eq!(loader_result.setup_header.unwrap().version, 0x20d);
243+
assert_eq!(
244+
// Reading the value from an unaligned address is not considered safe.
245+
unsafe { std::ptr::addr_of!(setup_header.header).read_unaligned() },
246+
0x53726448
247+
);
248+
assert_eq!(
249+
// Reading the value from an unaligned address is not considered safe.
250+
unsafe { std::ptr::addr_of!(setup_header.version).read_unaligned() },
251+
0x20d
252+
);
245253
assert_eq!(loader_result.setup_header.unwrap().loadflags, 1);
246254
assert_eq!(loader_result.kernel_end, 0x60D320);
247255

@@ -253,11 +261,16 @@ mod tests {
253261
Some(highmem_start_address),
254262
)
255263
.unwrap();
264+
let setup_header = loader_result.setup_header.unwrap();
265+
256266
assert_eq!(loader_result.kernel_load.raw_value(), 0x100000);
257267

258-
// load bzImage withouth himem_start
268+
// load bzImage without himem_start
259269
loader_result = BzImage::load(&gm, None, &mut Cursor::new(&image), None).unwrap();
260-
assert_eq!(0x53726448, loader_result.setup_header.unwrap().header);
270+
// Reading the value from an unaligned address is not considered safe.
271+
assert_eq!(0x53726448, unsafe {
272+
std::ptr::addr_of!(setup_header.header).read_unaligned()
273+
});
261274
assert_eq!(loader_result.kernel_load.raw_value(), 0x100000);
262275

263276
// load bzImage with a bad himem setting

0 commit comments

Comments
 (0)