mirror of
https://github.com/pbatard/rufus.git
synced 2025-05-22 02:45:11 -04:00
[misc] fix a crash when scanning a DD image with no UFD plugged in
* Also set the block size to 512 when scanning MBR and PBR * Closes #352
This commit is contained in:
parent
0fceb38433
commit
f6ab32c95d
3 changed files with 16 additions and 18 deletions
|
@ -527,7 +527,7 @@ BOOL AnalyzeMBR(HANDLE hPhysicalDrive, const char* TargetName)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
fake_fd._ptr = (char*)hPhysicalDrive;
|
fake_fd._ptr = (char*)hPhysicalDrive;
|
||||||
fake_fd._bufsiz = SelectedDrive.Geometry.BytesPerSector;
|
fake_fd._bufsiz = 512;
|
||||||
|
|
||||||
if (!is_br(&fake_fd)) {
|
if (!is_br(&fake_fd)) {
|
||||||
uprintf("%s does not have an x86 %s\n", TargetName, mbr_name);
|
uprintf("%s does not have an x86 %s\n", TargetName, mbr_name);
|
||||||
|
@ -562,7 +562,7 @@ BOOL AnalyzePBR(HANDLE hLogicalVolume)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
fake_fd._ptr = (char*)hLogicalVolume;
|
fake_fd._ptr = (char*)hLogicalVolume;
|
||||||
fake_fd._bufsiz = SelectedDrive.Geometry.BytesPerSector;
|
fake_fd._bufsiz = 512;
|
||||||
|
|
||||||
if (!is_br(&fake_fd)) {
|
if (!is_br(&fake_fd)) {
|
||||||
uprintf("Volume does not have an x86 %s\n", pbr_name);
|
uprintf("Volume does not have an x86 %s\n", pbr_name);
|
||||||
|
|
18
src/format.c
18
src/format.c
|
@ -848,8 +848,6 @@ static BOOL WriteMBR(HANDLE hPhysicalDrive)
|
||||||
DWORD size;
|
DWORD size;
|
||||||
int dt, fs, bt;
|
int dt, fs, bt;
|
||||||
unsigned char* buf = NULL;
|
unsigned char* buf = NULL;
|
||||||
size_t SecSize = SelectedDrive.Geometry.BytesPerSector;
|
|
||||||
size_t nSecs = (0x200 + SecSize -1) / SecSize;
|
|
||||||
FILE fake_fd = { 0 };
|
FILE fake_fd = { 0 };
|
||||||
const char* using_msg = "Using %s MBR\n";
|
const char* using_msg = "Using %s MBR\n";
|
||||||
|
|
||||||
|
@ -857,14 +855,14 @@ static BOOL WriteMBR(HANDLE hPhysicalDrive)
|
||||||
|
|
||||||
// FormatEx rewrites the MBR and removes the LBA attribute of FAT16
|
// FormatEx rewrites the MBR and removes the LBA attribute of FAT16
|
||||||
// and FAT32 partitions - we need to correct this in the MBR
|
// and FAT32 partitions - we need to correct this in the MBR
|
||||||
buf = (unsigned char*)malloc(SecSize * nSecs);
|
buf = (unsigned char*)malloc(512);
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
uprintf("Could not allocate memory for MBR");
|
uprintf("Could not allocate memory for MBR");
|
||||||
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_NOT_ENOUGH_MEMORY;
|
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_NOT_ENOUGH_MEMORY;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!read_sectors(hPhysicalDrive, SelectedDrive.Geometry.BytesPerSector, 0, nSecs, buf)) {
|
if (!read_sectors(hPhysicalDrive, 512, 0, 1, buf)) {
|
||||||
uprintf("Could not read MBR\n");
|
uprintf("Could not read MBR\n");
|
||||||
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_READ_FAULT;
|
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_READ_FAULT;
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -894,14 +892,14 @@ static BOOL WriteMBR(HANDLE hPhysicalDrive)
|
||||||
uprintf("Set bootable USB partition as 0x%02X\n", buf[0x1be]);
|
uprintf("Set bootable USB partition as 0x%02X\n", buf[0x1be]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!write_sectors(hPhysicalDrive, SecSize, 0, nSecs, buf)) {
|
if (!write_sectors(hPhysicalDrive, 512, 0, 1, buf)) {
|
||||||
uprintf("Could not write MBR\n");
|
uprintf("Could not write MBR\n");
|
||||||
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT;
|
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
fake_fd._ptr = (char*)hPhysicalDrive;
|
fake_fd._ptr = (char*)hPhysicalDrive;
|
||||||
fake_fd._bufsiz = SelectedDrive.Geometry.BytesPerSector;
|
fake_fd._bufsiz = 512;
|
||||||
fs = (int)ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem));
|
fs = (int)ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem));
|
||||||
dt = (int)ComboBox_GetItemData(hBootType, ComboBox_GetCurSel(hBootType));
|
dt = (int)ComboBox_GetItemData(hBootType, ComboBox_GetCurSel(hBootType));
|
||||||
bt = GETBIOSTYPE((int)ComboBox_GetItemData(hPartitionScheme, ComboBox_GetCurSel(hPartitionScheme)));
|
bt = GETBIOSTYPE((int)ComboBox_GetItemData(hPartitionScheme, ComboBox_GetCurSel(hPartitionScheme)));
|
||||||
|
@ -955,7 +953,7 @@ static BOOL WritePBR(HANDLE hLogicalVolume)
|
||||||
const char* using_msg = "Using %s %s partition boot record\n";
|
const char* using_msg = "Using %s %s partition boot record\n";
|
||||||
|
|
||||||
fake_fd._ptr = (char*)hLogicalVolume;
|
fake_fd._ptr = (char*)hLogicalVolume;
|
||||||
fake_fd._bufsiz = SelectedDrive.Geometry.BytesPerSector;
|
fake_fd._bufsiz = 512;
|
||||||
|
|
||||||
switch (ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem))) {
|
switch (ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem))) {
|
||||||
case FS_FAT16:
|
case FS_FAT16:
|
||||||
|
@ -999,7 +997,7 @@ static BOOL WritePBR(HANDLE hLogicalVolume)
|
||||||
// Disk Drive ID needs to be corrected on XP
|
// Disk Drive ID needs to be corrected on XP
|
||||||
if (!write_partition_physical_disk_drive_id_fat32(&fake_fd))
|
if (!write_partition_physical_disk_drive_id_fat32(&fake_fd))
|
||||||
break;
|
break;
|
||||||
fake_fd._cnt += 6 * (int)SelectedDrive.Geometry.BytesPerSector;
|
fake_fd._cnt += 6 * 512;
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
case FS_NTFS:
|
case FS_NTFS:
|
||||||
|
@ -1329,7 +1327,7 @@ DWORD WINAPI FormatThread(void* param)
|
||||||
uprintf("Bad blocks: Check failed.\n");
|
uprintf("Bad blocks: Check failed.\n");
|
||||||
if (!IS_ERROR(FormatStatus))
|
if (!IS_ERROR(FormatStatus))
|
||||||
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_BADBLOCKS_FAILURE);
|
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_BADBLOCKS_FAILURE);
|
||||||
ClearMBRGPT(hPhysicalDrive, SelectedDrive.DiskSize, SelectedDrive.Geometry.BytesPerSector, FALSE);
|
ClearMBRGPT(hPhysicalDrive, SelectedDrive.DiskSize, 512, FALSE);
|
||||||
fclose(log_fd);
|
fclose(log_fd);
|
||||||
_unlink(logfile);
|
_unlink(logfile);
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -1440,7 +1438,7 @@ DWORD WINAPI FormatThread(void* param)
|
||||||
|
|
||||||
// Especially after destructive badblocks test, you must zero the MBR/GPT completely
|
// Especially after destructive badblocks test, you must zero the MBR/GPT completely
|
||||||
// before repartitioning. Else, all kind of bad things happen.
|
// before repartitioning. Else, all kind of bad things happen.
|
||||||
if (!ClearMBRGPT(hPhysicalDrive, SelectedDrive.DiskSize, SelectedDrive.Geometry.BytesPerSector, use_large_fat32)) {
|
if (!ClearMBRGPT(hPhysicalDrive, SelectedDrive.DiskSize, 512, use_large_fat32)) {
|
||||||
uprintf("unable to zero MBR/GPT\n");
|
uprintf("unable to zero MBR/GPT\n");
|
||||||
if (!IS_ERROR(FormatStatus))
|
if (!IS_ERROR(FormatStatus))
|
||||||
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT;
|
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT;
|
||||||
|
|
12
src/rufus.rc
12
src/rufus.rc
|
@ -32,7 +32,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
|
||||||
|
|
||||||
IDD_DIALOG DIALOGEX 12, 12, 206, 329
|
IDD_DIALOG DIALOGEX 12, 12, 206, 329
|
||||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||||
CAPTION "Rufus 1.4.10.509"
|
CAPTION "Rufus 1.4.10.510"
|
||||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||||
BEGIN
|
BEGIN
|
||||||
DEFPUSHBUTTON "Start",IDC_START,94,291,50,14
|
DEFPUSHBUTTON "Start",IDC_START,94,291,50,14
|
||||||
|
@ -165,7 +165,7 @@ END
|
||||||
RTL_IDD_DIALOG DIALOGEX 12, 12, 206, 329
|
RTL_IDD_DIALOG DIALOGEX 12, 12, 206, 329
|
||||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||||
EXSTYLE WS_EX_RTLREADING | WS_EX_APPWINDOW | WS_EX_LAYOUTRTL
|
EXSTYLE WS_EX_RTLREADING | WS_EX_APPWINDOW | WS_EX_LAYOUTRTL
|
||||||
CAPTION "Rufus 1.4.10.509"
|
CAPTION "Rufus 1.4.10.510"
|
||||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||||
BEGIN
|
BEGIN
|
||||||
DEFPUSHBUTTON "Start",IDC_START,94,291,50,14
|
DEFPUSHBUTTON "Start",IDC_START,94,291,50,14
|
||||||
|
@ -428,8 +428,8 @@ END
|
||||||
//
|
//
|
||||||
|
|
||||||
VS_VERSION_INFO VERSIONINFO
|
VS_VERSION_INFO VERSIONINFO
|
||||||
FILEVERSION 1,4,10,509
|
FILEVERSION 1,4,10,510
|
||||||
PRODUCTVERSION 1,4,10,509
|
PRODUCTVERSION 1,4,10,510
|
||||||
FILEFLAGSMASK 0x3fL
|
FILEFLAGSMASK 0x3fL
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
FILEFLAGS 0x1L
|
FILEFLAGS 0x1L
|
||||||
|
@ -446,13 +446,13 @@ BEGIN
|
||||||
BEGIN
|
BEGIN
|
||||||
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)"
|
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)"
|
||||||
VALUE "FileDescription", "Rufus"
|
VALUE "FileDescription", "Rufus"
|
||||||
VALUE "FileVersion", "1.4.10.509"
|
VALUE "FileVersion", "1.4.10.510"
|
||||||
VALUE "InternalName", "Rufus"
|
VALUE "InternalName", "Rufus"
|
||||||
VALUE "LegalCopyright", "© 2011-2014 Pete Batard (GPL v3)"
|
VALUE "LegalCopyright", "© 2011-2014 Pete Batard (GPL v3)"
|
||||||
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
|
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
|
||||||
VALUE "OriginalFilename", "rufus.exe"
|
VALUE "OriginalFilename", "rufus.exe"
|
||||||
VALUE "ProductName", "Rufus"
|
VALUE "ProductName", "Rufus"
|
||||||
VALUE "ProductVersion", "1.4.10.509"
|
VALUE "ProductVersion", "1.4.10.510"
|
||||||
END
|
END
|
||||||
END
|
END
|
||||||
BLOCK "VarFileInfo"
|
BLOCK "VarFileInfo"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue