]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/VirtioFsDxe: convert FUSE dirent filename to EFI_FILE_INFO
authorLaszlo Ersek <lersek@redhat.com>
Wed, 16 Dec 2020 21:11:11 +0000 (22:11 +0100)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 21 Dec 2020 17:16:23 +0000 (17:16 +0000)
Introduce the VirtioFsFuseDirentPlusToEfiFileInfo() function, for
converting the VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE filename byte array to
EFI_FILE_INFO.

This new function updates those EFI_FILE_INFO fields (Size, FileName) that
the earlier helper function VirtioFsFuseAttrToEfiFileInfo() does not set.

Both functions together will be able to fill in EFI_FILE_INFO completely,
from FUSE_READDIRPLUS.

Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20201216211125.19496-35-lersek@redhat.com>
Acked-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
OvmfPkg/VirtioFsDxe/Helpers.c
OvmfPkg/VirtioFsDxe/VirtioFsDxe.h

index 5c3e990add0417c829c16653e8593f2a60114b55..dab8844f992d52886996572880fb92e7b2a0676b 100644 (file)
@@ -1900,3 +1900,82 @@ VirtioFsFuseAttrToEfiFileInfo (
 \r
   return EFI_SUCCESS;\r
 }\r
+\r
+/**\r
+  Convert a VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE filename to an EFI_FILE_INFO\r
+  filename.\r
+\r
+  @param[in] FuseDirent    The VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE object to\r
+                           convert the filename byte array from. The caller is\r
+                           responsible for ensuring that FuseDirent->Namelen\r
+                           describe valid storage.\r
+\r
+  @param[in,out] FileInfo  The EFI_FILE_INFO structure to modify. On input, the\r
+                           caller is responsible for setting FileInfo->Size\r
+                           according to the allocated size. On successful\r
+                           return, FileInfo->Size is reduced to reflect the\r
+                           filename converted into FileInfo->FileName.\r
+                           FileInfo->FileName is set from the filename byte\r
+                           array that directly follows the FuseDirent header\r
+                           object. Fields other than FileInfo->Size and\r
+                           FileInfo->FileName are not modified.\r
+\r
+  @retval EFI_SUCCESS            Conversion successful.\r
+\r
+  @retval EFI_INVALID_PARAMETER  VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE_SIZE()\r
+                                 returns zero for FuseDirent->Namelen.\r
+\r
+  @retval EFI_BUFFER_TOO_SMALL   On input, FileInfo->Size does not provide\r
+                                 enough room for converting the filename byte\r
+                                 array from FuseDirent.\r
+\r
+  @retval EFI_UNSUPPORTED        The FuseDirent filename byte array contains a\r
+                                 byte that falls outside of the printable ASCII\r
+                                 range, or is a forward slash or a backslash.\r
+**/\r
+EFI_STATUS\r
+VirtioFsFuseDirentPlusToEfiFileInfo (\r
+  IN     VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE *FuseDirent,\r
+  IN OUT EFI_FILE_INFO                      *FileInfo\r
+  )\r
+{\r
+  UINTN  DirentSize;\r
+  UINTN  FileInfoSize;\r
+  UINT8  *DirentName;\r
+  UINT32 Idx;\r
+\r
+  DirentSize = VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE_SIZE (FuseDirent->Namelen);\r
+  if (DirentSize == 0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // We're now safe from overflow in the calculation below.\r
+  //\r
+  FileInfoSize = (OFFSET_OF (EFI_FILE_INFO, FileName) +\r
+                  ((UINTN)FuseDirent->Namelen + 1) * sizeof (CHAR16));\r
+  if (FileInfoSize > FileInfo->Size) {\r
+    return EFI_BUFFER_TOO_SMALL;\r
+  }\r
+\r
+  //\r
+  // Convert the name.\r
+  //\r
+  DirentName = (UINT8 *)(FuseDirent + 1);\r
+  for (Idx = 0; Idx < FuseDirent->Namelen; Idx++) {\r
+    UINT8 NameByte;\r
+\r
+    NameByte = DirentName[Idx];\r
+    if (NameByte < 0x20 || NameByte > 0x7E ||\r
+        NameByte == '/' || NameByte == '\\') {\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+    FileInfo->FileName[Idx] = (CHAR16)NameByte;\r
+  }\r
+  FileInfo->FileName[Idx++] = L'\0';\r
+  //\r
+  // Set the (possibly reduced) size.\r
+  //\r
+  FileInfo->Size = FileInfoSize;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
index f5501af7d0a4f9f065e3a5539006c048bc40d4c3..2b419048c23225e2829f3ba456de707068d09c75 100644 (file)
@@ -248,6 +248,12 @@ VirtioFsFuseAttrToEfiFileInfo (
      OUT EFI_FILE_INFO                      *FileInfo\r
   );\r
 \r
+EFI_STATUS\r
+VirtioFsFuseDirentPlusToEfiFileInfo (\r
+  IN     VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE *FuseDirent,\r
+  IN OUT EFI_FILE_INFO                      *FileInfo\r
+  );\r
+\r
 //\r
 // Wrapper functions for FUSE commands (primitives).\r
 //\r