writembr: Fix too short MBR due to wrong compile flags.
The compile flags were set so that only the boot code itself would be produced, excluding the (dummy) partition table and signature. The code in writembr still assumed that the MBR would be 512 bytes however and therefore access the data array out of bounds. Fix flags to produce the full 512 byte MBR sector and add a STATIC_ASSERT so that the size assumption is checked on compilation. Also fix a typo in mbr.nasm, mostly to trigger re-generation of the MBR data that one would otherwise need to remove manually... The two out of bounds array accesses were pointed out by CID 1249923 and CID 1249924, the insufficiently large target buffer of the memcpy by CID 1249901.
This commit is contained in:
@@ -10,7 +10,7 @@ Application writembr :
|
||||
|
||||
# Assemble the MBR code, and convert it into a header file
|
||||
|
||||
NASMFLAGS on [ FGristFiles mbr.bin ] = -f bin -O5 -dMBR_CODE_ONLY=1 ;
|
||||
NASMFLAGS on [ FGristFiles mbr.bin ] = -f bin -O5 ;
|
||||
|
||||
Object [ FGristFiles mbr.bin ] : mbr.nasm ;
|
||||
|
||||
|
||||
@@ -218,7 +218,7 @@ found_active: ; active partition (pointed by si)
|
||||
mov [address_packet+AddressPacket.sector],eax
|
||||
|
||||
; if LBA_adress equals 0 then it's not a valid PBR (it is the MBR)
|
||||
; this can append when we only have a CHS adress in the partition entry
|
||||
; this can happen when we only have a CHS adress in the partition entry
|
||||
test eax, eax ;if ( LBA_adress == 0 )
|
||||
jz no_disk_extentions ;then no_disk_extentions()
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
|
||||
#include <Debug.h>
|
||||
#include <DiskDevice.h>
|
||||
#include <DiskDeviceRoster.h>
|
||||
#include <Path.h>
|
||||
@@ -73,6 +74,8 @@ main(int argc, char** argv)
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
STATIC_ASSERT(kMBRSize == 512);
|
||||
|
||||
unsigned char MBR[kMBRSize];
|
||||
fs.read((char*)MBR, kMBRSize);
|
||||
if (fs.fail() || fs.gcount() < kMBRSize ) {
|
||||
|
||||
Reference in New Issue
Block a user