1
1
Fork 0
mirror of https://github.com/pbatard/rufus.git synced 2024-08-14 23:57:05 +00:00

[misc] use %S to print wchar_t strings where possible

* Also fix some Coverity warnings
This commit is contained in:
Pete Batard 2019-01-03 12:29:28 +00:00
parent 5309dc88e2
commit befe2606cf
No known key found for this signature in database
GPG key ID: 38E0CF5E69EDD671
5 changed files with 17 additions and 27 deletions

View file

@ -926,7 +926,7 @@ BOOL GetDrivePartitionData(DWORD DriveIndex, char* FileSystemName, DWORD FileSys
BYTE geometry[256] = {0}, layout[4096] = {0}, part_type; BYTE geometry[256] = {0}, layout[4096] = {0}, part_type;
PDISK_GEOMETRY_EX DiskGeometry = (PDISK_GEOMETRY_EX)(void*)geometry; PDISK_GEOMETRY_EX DiskGeometry = (PDISK_GEOMETRY_EX)(void*)geometry;
PDRIVE_LAYOUT_INFORMATION_EX DriveLayout = (PDRIVE_LAYOUT_INFORMATION_EX)(void*)layout; PDRIVE_LAYOUT_INFORMATION_EX DriveLayout = (PDRIVE_LAYOUT_INFORMATION_EX)(void*)layout;
char *volume_name, *buf, tmp[256]; char *volume_name, *buf;
if (FileSystemName == NULL) if (FileSystemName == NULL)
return FALSE; return FALSE;
@ -1046,11 +1046,9 @@ BOOL GetDrivePartitionData(DWORD DriveIndex, char* FileSystemName, DWORD FileSys
DriveLayout->Gpt.MaxPartitionCount, DriveLayout->Gpt.StartingUsableOffset.QuadPart, DriveLayout->Gpt.UsableLength.QuadPart); DriveLayout->Gpt.MaxPartitionCount, DriveLayout->Gpt.StartingUsableOffset.QuadPart, DriveLayout->Gpt.UsableLength.QuadPart);
for (i=0; i<DriveLayout->PartitionCount; i++) { for (i=0; i<DriveLayout->PartitionCount; i++) {
SelectedDrive.nPartitions++; SelectedDrive.nPartitions++;
tmp[0] = 0; isUefiNtfs = (wcscmp(DriveLayout->PartitionEntry[i].Gpt.Name, L"UEFI:NTFS") == 0);
wchar_to_utf8_no_alloc(DriveLayout->PartitionEntry[i].Gpt.Name, tmp, sizeof(tmp)); suprintf("Partition %d%s:\r\n Type: %s\r\n Name: '%S'", i+1, isUefiNtfs ? " (UEFI:NTFS)" : "",
isUefiNtfs = (strcmp(tmp, "UEFI:NTFS") == 0); GuidToString(&DriveLayout->PartitionEntry[i].Gpt.PartitionType), DriveLayout->PartitionEntry[i].Gpt.Name);
suprintf("Partition %d%s:\r\n Type: %s\r\n Name: '%s'", i+1, isUefiNtfs ? " (UEFI:NTFS)" : "",
GuidToString(&DriveLayout->PartitionEntry[i].Gpt.PartitionType), tmp);
suprintf(" ID: %s\r\n Size: %s (%" PRIi64 " bytes)\r\n Start Sector: %" PRIi64 ", Attributes: 0x%016" PRIX64, suprintf(" ID: %s\r\n Size: %s (%" PRIi64 " bytes)\r\n Start Sector: %" PRIi64 ", Attributes: 0x%016" PRIX64,
GuidToString(&DriveLayout->PartitionEntry[i].Gpt.PartitionId), GuidToString(&DriveLayout->PartitionEntry[i].Gpt.PartitionId),
SizeToHumanReadable(DriveLayout->PartitionEntry[i].PartitionLength.QuadPart, TRUE, FALSE), SizeToHumanReadable(DriveLayout->PartitionEntry[i].PartitionLength.QuadPart, TRUE, FALSE),

View file

@ -73,7 +73,6 @@ static BOOL WritePBR(HANDLE hLogicalDrive);
static void OutputUTF8Message(const char* src) static void OutputUTF8Message(const char* src)
{ {
int len; int len;
char *dst = NULL;
wchar_t* wdst = NULL; wchar_t* wdst = NULL;
if (src == NULL) if (src == NULL)
@ -90,13 +89,9 @@ static void OutputUTF8Message(const char* src)
wdst = (wchar_t*)calloc(len+1, sizeof(wchar_t)); wdst = (wchar_t*)calloc(len+1, sizeof(wchar_t));
if ((wdst == NULL) || (MultiByteToWideChar(CP_OEMCP, 0, src, len, wdst, len+1) == 0)) if ((wdst == NULL) || (MultiByteToWideChar(CP_OEMCP, 0, src, len, wdst, len+1) == 0))
goto out; goto out;
dst = wchar_to_utf8(wdst); uprintf("%S", wdst);
if (dst == NULL)
goto out;
uprintf("%s", dst);
out: out:
safe_free(dst);
safe_free(wdst); safe_free(wdst);
} }

View file

@ -405,6 +405,8 @@ static PWSTR GetProcessCommandLine(HANDLE hProcess)
goto out; goto out;
ucmdline = (UNICODE_STRING*)(pp + cmd_offset); ucmdline = (UNICODE_STRING*)(pp + cmd_offset);
// In the absolute, someone could craft a process with dodgy attributes to try to cause an overflow
ucmdline->Length = min(ucmdline->Length, 512);
wcmdline = (PWSTR)calloc(ucmdline->Length + 1, sizeof(WCHAR)); wcmdline = (PWSTR)calloc(ucmdline->Length + 1, sizeof(WCHAR));
if (!ReadProcessMemory(hProcess, ucmdline->Buffer, wcmdline, ucmdline->Length, NULL)) { if (!ReadProcessMemory(hProcess, ucmdline->Buffer, wcmdline, ucmdline->Length, NULL)) {
safe_free(wcmdline); safe_free(wcmdline);
@ -433,7 +435,7 @@ static DWORD WINAPI SearchProcessThread(LPVOID param)
WCHAR *wHandleName = NULL; WCHAR *wHandleName = NULL;
HANDLE dupHandle = NULL; HANDLE dupHandle = NULL;
HANDLE processHandle = NULL; HANDLE processHandle = NULL;
BOOLEAN bFound = FALSE, bGotCmdLine, verbose = !_bQuiet; BOOLEAN bFound = FALSE, bGotCmdLine = FALSE, verbose = !_bQuiet;
ULONG access_rights = 0; ULONG access_rights = 0;
DWORD size; DWORD size;
char cmdline[MAX_PATH] = { 0 }; char cmdline[MAX_PATH] = { 0 };

View file

@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 232, 326 IDD_DIALOG DIALOGEX 12, 12, 232, 326
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_ACCEPTFILES EXSTYLE WS_EX_ACCEPTFILES
CAPTION "Rufus 3.5.1435" CAPTION "Rufus 3.5.1436"
FONT 9, "Segoe UI Symbol", 400, 0, 0x0 FONT 9, "Segoe UI Symbol", 400, 0, 0x0
BEGIN BEGIN
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
@ -394,8 +394,8 @@ END
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,5,1435,0 FILEVERSION 3,5,1436,0
PRODUCTVERSION 3,5,1435,0 PRODUCTVERSION 3,5,1436,0
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -413,13 +413,13 @@ BEGIN
VALUE "Comments", "https://akeo.ie" VALUE "Comments", "https://akeo.ie"
VALUE "CompanyName", "Akeo Consulting" VALUE "CompanyName", "Akeo Consulting"
VALUE "FileDescription", "Rufus" VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "3.5.1435" VALUE "FileVersion", "3.5.1436"
VALUE "InternalName", "Rufus" VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2018 Pete Batard (GPL v3)" VALUE "LegalCopyright", "© 2011-2018 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "https://www.gnu.org/copyleft/gpl.html" VALUE "LegalTrademarks", "https://www.gnu.org/copyleft/gpl.html"
VALUE "OriginalFilename", "rufus-3.5.exe" VALUE "OriginalFilename", "rufus-3.5.exe"
VALUE "ProductName", "Rufus" VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "3.5.1435" VALUE "ProductVersion", "3.5.1436"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

View file

@ -564,7 +564,6 @@ DWORD WINAPI WimProgressCallback(DWORD dwMsgId, WPARAM wParam, LPARAM lParam, PV
{ {
PBOOL pbCancel = NULL; PBOOL pbCancel = NULL;
PWIN32_FIND_DATA pFileData; PWIN32_FIND_DATA pFileData;
char* str = NULL;
const char* level = NULL; const char* level = NULL;
uint64_t size; uint64_t size;
float apply_percent; float apply_percent;
@ -582,8 +581,7 @@ DWORD WINAPI WimProgressCallback(DWORD dwMsgId, WPARAM wParam, LPARAM lParam, PV
// The amount of files processed is overwhelming (16k+ for a typical image), // The amount of files processed is overwhelming (16k+ for a typical image),
// and trying to display it *WILL* slow us down, so we don't. // and trying to display it *WILL* slow us down, so we don't.
#if 0 #if 0
str = wchar_to_utf8((PWSTR)wParam); uprintf("%S", (PWSTR)wParam);
uprintf("%s", str);
PrintStatus(0, MSG_000, str); // MSG_000 is "%s" PrintStatus(0, MSG_000, str); // MSG_000 is "%s"
#endif #endif
if (count_files) { if (count_files) {
@ -612,13 +610,12 @@ DWORD WINAPI WimProgressCallback(DWORD dwMsgId, WPARAM wParam, LPARAM lParam, PV
} }
break; break;
case WIM_MSG_FILEINFO: case WIM_MSG_FILEINFO:
str = wchar_to_utf8((PWSTR)wParam);
pFileData = (PWIN32_FIND_DATA)lParam; pFileData = (PWIN32_FIND_DATA)lParam;
if (pFileData->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if (pFileData->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
uprintf("Creating: %s", str); uprintf("Creating: %S", (PWSTR)wParam);
} else { } else {
size = (((uint64_t)pFileData->nFileSizeHigh) << 32) + pFileData->nFileSizeLow; size = (((uint64_t)pFileData->nFileSizeHigh) << 32) + pFileData->nFileSizeLow;
uprintf("Extracting: %s (%s)", str, SizeToHumanReadable(size, FALSE, FALSE)); uprintf("Extracting: %S (%s)", (PWSTR)wParam, SizeToHumanReadable(size, FALSE, FALSE));
} }
break; break;
case WIM_MSG_RETRY: case WIM_MSG_RETRY:
@ -632,12 +629,10 @@ DWORD WINAPI WimProgressCallback(DWORD dwMsgId, WPARAM wParam, LPARAM lParam, PV
// fall through // fall through
case WIM_MSG_ERROR: case WIM_MSG_ERROR:
if (level == NULL) level = "error"; if (level == NULL) level = "error";
str = wchar_to_utf8((PWSTR)wParam);
SetLastError((DWORD)lParam); SetLastError((DWORD)lParam);
uprintf("Apply %s: %s [err = %d]\n", level, str, WindowsErrorString()); uprintf("Apply %s: %S [err = %d]\n", level, (PWSTR)wParam, WindowsErrorString());
break; break;
} }
safe_free(str);
return IS_ERROR(FormatStatus)?WIM_MSG_ABORT_IMAGE:WIM_MSG_SUCCESS; return IS_ERROR(FormatStatus)?WIM_MSG_ABORT_IMAGE:WIM_MSG_SUCCESS;
} }