Skip to content

Commit 9903767

Browse files
committed
fix use of Print() modifiers that aren't available to EDK2
* gnu-efi uses various %# Print() extensions that aren't found in EDK2, such as %D to print a device path => remove them. * Also fix display of the NTFS volume label for UEFI firmwares that require GetInfo() to pass the exact size of the label. * Also fix wrong project name in security notice.
1 parent 9656dbb commit 9903767

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

SECURITY.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Reporting a Vulnerability
22

3-
To report a vulnerability for Rufus, please e-mail [email protected].
3+
To report a vulnerability for UEFI:NTFS, please e-mail [email protected].
44

55
If you find a vulnerability, we will ask you to respect [responsible disclosure](https://en.wikipedia.org/wiki/Responsible_disclosure) practices.
66

boot.c

+21-10
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static CHAR16* GetDriverName(CONST EFI_HANDLE DriverHandle)
7878
* To fix it we disconnect drivers that connected to DiskIo BY_DRIVER if this
7979
* is a partition volume and if those drivers did not produce file system.
8080
*
81-
* This code was originally derived from similar BSD-3-Clause license one
81+
* This code was originally derived from similar BSD-3-Clause licensed one
8282
* (a.k.a. Modified BSD License, which can be used in GPLv2+ works), found at:
8383
* https://sourceforge.net/p/cloverefiboot/code/3294/tree/rEFIt_UEFI/refit/main.c#l1271
8484
*/
@@ -202,9 +202,9 @@ static EFI_STATUS PrintSystemInfo(VOID)
202202
SecureBootStatus = -1;
203203
// Wasteful, but we can't highlight "Enabled"/"Setup" from a %s argument...
204204
if (SecureBootStatus > 0)
205-
PrintInfo(L"Secure Boot status: %HEnabled%N");
205+
PrintInfo(L"Secure Boot status: Enabled");
206206
else if (SecureBootStatus < 0)
207-
PrintInfo(L"Secure Boot status: %ESetup%N");
207+
PrintInfo(L"Secure Boot status: Setup");
208208
else
209209
PrintInfo(L"Secure Boot status: Disabled");
210210

@@ -222,6 +222,7 @@ EFI_STATUS EFIAPI efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable
222222
CONST CHAR16* FsName[] = { L"NTFS", L"exFAT" };
223223
CONST CHAR16* DriverName[] = { L"ntfs", L"exfat" };
224224
CHAR16 DriverPath[64], LoaderPath[64];
225+
CHAR16* DevicePathString;
225226
EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
226227
EFI_STATUS Status;
227228
EFI_DEVICE_PATH *DevicePath, *ParentDevicePath = NULL, *BootDiskPath = NULL;
@@ -245,7 +246,7 @@ EFI_STATUS EFIAPI efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable
245246
// The platform logo may still be displayed → remove it
246247
SystemTable->ConOut->ClearScreen(SystemTable->ConOut);
247248

248-
Print(L"\n%H*** UEFI:NTFS %s (%s) ***%N\n\n", VERSION_STRING, Arch);
249+
Print(L"\n*** UEFI:NTFS %s (%s) ***\n\n", VERSION_STRING, Arch);
249250
#if defined(_GNU_EFI)
250251
PrintSystemInfo();
251252
#endif
@@ -265,7 +266,9 @@ EFI_STATUS EFIAPI efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable
265266
BootDiskPath = GetParentDevice(BootPartitionPath);
266267

267268
PrintInfo(L"Searching for target partition on boot disk:");
268-
PrintInfo(L" %D", BootDiskPath);
269+
DevicePathString = DevicePathToString(BootDiskPath);
270+
PrintInfo(L" %s", DevicePathString);
271+
SafeFree(DevicePathString);
269272
// Enumerate all disk handles
270273
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiDiskIoProtocolGuid,
271274
NULL, &HandleCount, &Handles);
@@ -318,7 +321,9 @@ EFI_STATUS EFIAPI efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable
318321
goto out;
319322
}
320323
PrintInfo(L"Found %s target partition:", FsName[FsType]);
321-
PrintInfo(L" %D", DevicePath);
324+
DevicePathString = DevicePathToString(DevicePath);
325+
PrintInfo(L" %s", DevicePathString);
326+
SafeFree(DevicePathString);
322327

323328
PrintInfo(L"Checking if target partition needs the %s service", FsName[FsType]);
324329
// Test for presence of file system protocol (to see if there already is
@@ -327,10 +332,10 @@ EFI_STATUS EFIAPI efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable
327332
(VOID**)&Volume, MainImageHandle, NULL, EFI_OPEN_PROTOCOL_TEST_PROTOCOL);
328333
if (Status == EFI_SUCCESS) {
329334
// A filesystem driver is already set => no need to start ours
330-
PrintWarning(L" An %s service is already loaded", FsName[FsType]);
335+
PrintWarning(L" An %s driver service is already loaded", FsName[FsType]);
331336
} else if (Status == EFI_UNSUPPORTED) {
332337
// Partition is not being serviced by a file system driver yet => start ours
333-
PrintInfo(L"Starting %s partition service:", FsName[FsType]);
338+
PrintInfo(L"Starting %s driver service:", FsName[FsType]);
334339

335340
// Use 'rufus' in the driver path, so that we don't accidentally latch onto a user driver
336341
UnicodeSPrint(DriverPath, ARRAY_SIZE(DriverPath), L"\\efi\\rufus\\%s_%s.efi", DriverName[FsType], Arch);
@@ -424,8 +429,14 @@ EFI_STATUS EFIAPI efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable
424429
VolumeInfo = (EFI_FILE_SYSTEM_VOLUME_LABEL*)AllocateZeroPool(Size);
425430
if (VolumeInfo != NULL) {
426431
Status = Root->GetInfo(Root, &gEfiFileSystemVolumeLabelInfoIdGuid, &Size, VolumeInfo);
427-
if ((Status == EFI_SUCCESS) && (VolumeInfo->VolumeLabel[0] != 0))
432+
// Some UEFI firmwares return EFI_BUFFER_TOO_SMALL, even with
433+
// a large enough buffer, unless the exact size is requested.
434+
if ((Status == EFI_BUFFER_TOO_SMALL) && (Size <= FILE_INFO_SIZE))
435+
Status = Root->GetInfo(Root, &gEfiFileSystemVolumeLabelInfoIdGuid, &Size, VolumeInfo);
436+
if (Status == EFI_SUCCESS)
428437
PrintInfo(L" Volume label is '%s'", VolumeInfo->VolumeLabel);
438+
else
439+
PrintWarning(L" Could not read volume label: [%d] %r\n", (Status & 0x7FFFFFFF), Status);
429440
FreePool(VolumeInfo);
430441
}
431442

@@ -467,7 +478,7 @@ EFI_STATUS EFIAPI efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable
467478

468479
// Wait for a keystroke on error
469480
if (EFI_ERROR(Status)) {
470-
Print(L"%H\nPress any key to exit.%N\n");
481+
Print(L"\nPress any key to exit.\n");
471482
gST->ConIn->Reset(gST->ConIn, FALSE);
472483
gST->BootServices->WaitForEvent(1, &gST->ConIn->WaitForKey, &Event);
473484
}

boot.h

+2-9
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,10 @@
8282

8383
/*
8484
* Convenience macros to print informational, warning or error messages.
85-
* NB: In addition to the standard %-based flags, Print() supports the following:
86-
* %N Set output attribute to normal
87-
* %H Set output attribute to highlight
88-
* %E Set output attribute to error
89-
* %B Set output attribute to blue color
90-
* %V Set output attribute to green color
91-
* %r Human readable version of a status code
9285
*/
9386
#define PrintInfo(fmt, ...) Print(L"[INFO] " fmt L"\n", ##__VA_ARGS__)
94-
#define PrintWarning(fmt, ...) Print(L"%E[WARN] " fmt L"%N\n", ##__VA_ARGS__)
95-
#define PrintError(fmt, ...) Print(L"%E[FAIL] " fmt L": [%d] %r%N\n", ##__VA_ARGS__, (Status&0x7FFFFFFF), Status)
87+
#define PrintWarning(fmt, ...) Print(L"[WARN] " fmt L"\n", ##__VA_ARGS__)
88+
#define PrintError(fmt, ...) Print(L"[FAIL] " fmt L": [%d] %r\n", ##__VA_ARGS__, (Status&0x7FFFFFFF), Status)
9689

9790
/* Convenience assertion macro */
9891
#define P_ASSERT(f, l, a) if(!(a)) do { Print(L"*** ASSERT FAILED: %a(%d): %a ***\n", f, l, #a); while(1); } while(0)

0 commit comments

Comments
 (0)