bug-grub
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Errors in multiboot kernel example code


From: Rodrigo Valiña Gutiérrez
Subject: Errors in multiboot kernel example code
Date: Sat, 4 Oct 2014 18:54:07 +0200

I was testing the kernel example code of the multiboot specification,
and found that it prints wrong memory base_addr and length values.
In the code found at the URLs:

https://www.gnu.org/software/grub/manual/multiboot/html_node/kernel_002ec.html

and, among others,

https://www.gnu.org/software/grub/manual/multiboot/multiboot.html

where reads:

             printf (" size = 0x%x, base_addr = 0x%x%x,"
                     " length = 0x%x%x, type = 0x%x\n",
                     (unsigned) mmap->size,
                     mmap->addr >> 32,
                     mmap->addr & 0xffffffff,
                     mmap->len >> 32,
                     mmap->len & 0xffffffff,
                     (unsigned) mmap->type);

should read:

             printf (" size = 0x%x, base_addr = 0x%x%x,"
                     " length = 0x%x%x, type = 0x%x\n",
                     (unsigned) mmap->size,
                     (unsigned)(mmap->addr >> 32),
                     (unsigned)(mmap->addr & 0xffffffff),
                     (unsigned)(mmap->len >> 32),
                     (unsigned)(mmap->len & 0xffffffff),
                     (unsigned) mmap->type);

Since arguments are pushed to the stack to printf, we should cast 64
bit values to 32 bit ones, as long as the implementation of printf
only handles 32 bit arguments. Otherwise the printed values are
incorrect, even when they fit in 32 bits.

Moreover, if the values do not fit in 32 bits, the printed values may
be incorrect, since there is no 0-padding for the low half of both
addr and len.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]