Skip to content

Commit eab12d3

Browse files
committed
multiboot.c: fix unsafe cast to uint32_t* from uint8_t*
note that this is not a problem on x86_64 architecture.
1 parent 7ebfab1 commit eab12d3

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/multiboot.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,18 +350,19 @@ static void mb2_dump_header(void* mbHeader) {
350350

351351
uint8_t *mb2_find_header(uint8_t *image, int size)
352352
{
353-
uint32_t *ptr;
353+
uint32_t val;
354354
int i;
355355

356356
if (size > MB2_HEADER_MAX_OFF)
357357
size = MB2_HEADER_MAX_OFF;
358358
size = size / 4;
359-
for (ptr = (uint32_t*)image,i = 0; i < size; ++i) {
360-
if (ptr[i] == MB2_HEADER_MAGIC) {
359+
for (i = 0; i < size; ++i) {
360+
memcpy(&val, image + i * 4, sizeof(val));
361+
if (val == MB2_HEADER_MAGIC) {
361362
#ifdef DEBUG_MB2
362-
mb2_dump_header(&ptr[i]);
363+
mb2_dump_header(image + i * 4);
363364
#endif /* DEBUG_MB2 */
364-
return (uint8_t*)&ptr[i];
365+
return image + i * 4;
365366
}
366367
}
367368
return NULL;

0 commit comments

Comments
 (0)