public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Hao Wu <hao.a.wu@intel.com>
To: edk2-devel@lists.01.org
Cc: Hao Wu <hao.a.wu@intel.com>, Paulo Alcantara <paulo@paulo.ac>,
	Ruiyu Ni <ruiyu.ni@intel.com>, Star Zeng <star.zeng@intel.com>
Subject: [PATCH v1 08/10] MdeModulePkg/UdfDxe: Update GetInfo() for FS VolumeLabel info request
Date: Tue, 16 Oct 2018 15:23:38 +0800	[thread overview]
Message-ID: <20181016072340.22068-9-hao.a.wu@intel.com> (raw)
In-Reply-To: <20181016072340.22068-1-hao.a.wu@intel.com>

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1175

This commit will update the UdfGetInfo() function with the support of
EFI_FILE_SYSTEM_VOLUME_LABEL data information request.

Cc: Paulo Alcantara <paulo@paulo.ac>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 MdeModulePkg/Universal/Disk/UdfDxe/File.c                 | 97 +++++++-------------
 MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c | 84 +++++++++++++++++
 MdeModulePkg/Universal/Disk/UdfDxe/Udf.h                  | 27 ++++++
 MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf             |  1 +
 4 files changed, 146 insertions(+), 63 deletions(-)

diff --git a/MdeModulePkg/Universal/Disk/UdfDxe/File.c b/MdeModulePkg/Universal/Disk/UdfDxe/File.c
index 54c2400243..eb91e877ee 100644
--- a/MdeModulePkg/Universal/Disk/UdfDxe/File.c
+++ b/MdeModulePkg/Universal/Disk/UdfDxe/File.c
@@ -718,12 +718,6 @@ UdfSetPosition (
 /**
   Get information about a file.
 
-  @attention This is boundary function that may receive untrusted input.
-  @attention The input is from FileSystem.
-
-  The File Set Descriptor is external input, so this routine will do basic
-  validation for File Set Descriptor and report status.
-
   @param  This            Protocol instance pointer.
   @param  InformationType Type of information to return in Buffer.
   @param  BufferSize      On input size of buffer, on output amount of data in
@@ -750,19 +744,16 @@ UdfGetInfo (
   OUT     VOID               *Buffer
   )
 {
-  EFI_STATUS                  Status;
-  PRIVATE_UDF_FILE_DATA       *PrivFileData;
-  PRIVATE_UDF_SIMPLE_FS_DATA  *PrivFsData;
-  EFI_FILE_SYSTEM_INFO        *FileSystemInfo;
-  UINTN                       FileSystemInfoLength;
-  CHAR16                      *String;
-  UDF_FILE_SET_DESCRIPTOR     *FileSetDesc;
-  UINTN                       Index;
-  UINT8                       *OstaCompressed;
-  UINT8                       CompressionId;
-  UINT64                      VolumeSize;
-  UINT64                      FreeSpaceSize;
-  CHAR16                      VolumeLabel[64];
+  EFI_STATUS                    Status;
+  PRIVATE_UDF_FILE_DATA         *PrivFileData;
+  PRIVATE_UDF_SIMPLE_FS_DATA    *PrivFsData;
+  EFI_FILE_SYSTEM_INFO          *FileSystemInfo;
+  UINTN                         FileSystemInfoLength;
+  UINT64                        VolumeSize;
+  UINT64                        FreeSpaceSize;
+  EFI_FILE_SYSTEM_VOLUME_LABEL  *FileSystemVolumeLabel;
+  UINTN                         FileSystemVolumeLabelLength;
+  CHAR16                        VolumeLabel[64];
 
   if (This == NULL || InformationType == NULL || BufferSize == NULL ||
       (*BufferSize != 0 && Buffer == NULL)) {
@@ -784,50 +775,10 @@ UdfGetInfo (
       Buffer
       );
   } else if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) {
-    String = VolumeLabel;
-
-    FileSetDesc = &PrivFsData->Volume.FileSetDesc;
-
-    OstaCompressed = &FileSetDesc->LogicalVolumeIdentifier[0];
-
-    CompressionId = OstaCompressed[0];
-    if (!IS_VALID_COMPRESSION_ID (CompressionId)) {
-      return EFI_VOLUME_CORRUPTED;
-    }
-
-    for (Index = 1; Index < 128; Index++) {
-      if (CompressionId == 16) {
-        *String = *(UINT8 *)(OstaCompressed + Index) << 8;
-        Index++;
-      } else {
-        if (Index > ARRAY_SIZE (VolumeLabel)) {
-          return EFI_VOLUME_CORRUPTED;
-        }
-
-        *String = 0;
-      }
-
-      if (Index < 128) {
-        *String |= (CHAR16)(*(UINT8 *)(OstaCompressed + Index));
-      }
-
-      //
-      // Unlike FID Identifiers, Logical Volume Identifier is stored in a
-      // NULL-terminated OSTA compressed format, so we must check for the NULL
-      // character.
-      //
-      if (*String == L'\0') {
-        break;
-      }
-
-      String++;
-    }
-
-    Index = ((UINTN)String - (UINTN)VolumeLabel) / sizeof (CHAR16);
-    if (Index > ARRAY_SIZE (VolumeLabel) - 1) {
-      Index = ARRAY_SIZE (VolumeLabel) - 1;
+    Status = GetVolumeLabel (&PrivFsData->Volume, ARRAY_SIZE (VolumeLabel), VolumeLabel);
+    if (EFI_ERROR (Status)) {
+      return Status;
     }
-    VolumeLabel[Index] = L'\0';
 
     FileSystemInfoLength = StrSize (VolumeLabel) +
                            sizeof (EFI_FILE_SYSTEM_INFO);
@@ -839,7 +790,7 @@ UdfGetInfo (
     FileSystemInfo = (EFI_FILE_SYSTEM_INFO *)Buffer;
     StrCpyS (
       FileSystemInfo->VolumeLabel,
-      (*BufferSize - OFFSET_OF (EFI_FILE_SYSTEM_INFO, VolumeLabel)) / sizeof (CHAR16),
+      (*BufferSize - SIZE_OF_EFI_FILE_SYSTEM_INFO) / sizeof (CHAR16),
       VolumeLabel
       );
     Status = GetVolumeSize (
@@ -862,6 +813,26 @@ UdfGetInfo (
 
     *BufferSize = FileSystemInfoLength;
     Status = EFI_SUCCESS;
+  } else if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) {
+    Status = GetVolumeLabel (&PrivFsData->Volume, ARRAY_SIZE (VolumeLabel), VolumeLabel);
+    if (EFI_ERROR (Status)) {
+      return Status;
+    }
+
+    FileSystemVolumeLabelLength = StrSize (VolumeLabel) +
+                                  sizeof (EFI_FILE_SYSTEM_VOLUME_LABEL);
+    if (*BufferSize < FileSystemVolumeLabelLength) {
+      *BufferSize = FileSystemVolumeLabelLength;
+      return EFI_BUFFER_TOO_SMALL;
+    }
+
+    FileSystemVolumeLabel = (EFI_FILE_SYSTEM_VOLUME_LABEL *)Buffer;
+    StrCpyS (
+      FileSystemVolumeLabel->VolumeLabel,
+      (*BufferSize - SIZE_OF_EFI_FILE_SYSTEM_VOLUME_LABEL) / sizeof (CHAR16),
+      VolumeLabel
+      );
+    Status = EFI_SUCCESS;
   }
 
   return Status;
diff --git a/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c b/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c
index ac6e0a8ff7..562a7d983c 100644
--- a/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c
+++ b/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c
@@ -2448,6 +2448,90 @@ SetFileInfo (
 }
 
 /**
+  Get volume label of an UDF volume.
+
+  @attention This is boundary function that may receive untrusted input.
+  @attention The input is from FileSystem.
+
+  The File Set Descriptor is external input, so this routine will do basic
+  validation for File Set Descriptor and report status.
+
+  @param[in]   Volume   Volume information pointer.
+  @param[in]   CharMax  The maximum number of Unicode char in String,
+                        including terminating null char.
+  @param[out]  String   String buffer pointer to store the volume label.
+
+  @retval EFI_SUCCESS           Volume label is returned.
+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.
+  @retval EFI_BUFFER_TOO_SMALL  The string buffer String cannot hold the
+                                volume label.
+
+**/
+EFI_STATUS
+GetVolumeLabel (
+  IN   UDF_VOLUME_INFO  *Volume,
+  IN   UINTN            CharMax,
+  OUT  CHAR16           *String
+  )
+{
+  UDF_FILE_SET_DESCRIPTOR  *FileSetDesc;
+  UINTN                    Index;
+  UINT8                    *OstaCompressed;
+  UINT8                    CompressionId;
+  CHAR16                   *StringBak;
+
+  FileSetDesc = &Volume->FileSetDesc;
+
+  OstaCompressed = &FileSetDesc->LogicalVolumeIdentifier[0];
+
+  CompressionId = OstaCompressed[0];
+  if (!IS_VALID_COMPRESSION_ID (CompressionId)) {
+    return EFI_VOLUME_CORRUPTED;
+  }
+
+  StringBak = String;
+  for (Index = 1; Index < 128; Index++) {
+    if (CompressionId == 16) {
+      if ((Index >> 1) > CharMax) {
+        return EFI_BUFFER_TOO_SMALL;
+      }
+
+      *String = *(UINT8 *)(OstaCompressed + Index) << 8;
+      Index++;
+    } else {
+      if (Index > CharMax) {
+        return EFI_BUFFER_TOO_SMALL;
+      }
+
+      *String = 0;
+    }
+
+    if (Index < 128) {
+      *String |= (CHAR16)(*(UINT8 *)(OstaCompressed + Index));
+    }
+
+    //
+    // Unlike FID Identifiers, Logical Volume Identifier is stored in a
+    // NULL-terminated OSTA compressed format, so we must check for the NULL
+    // character.
+    //
+    if (*String == L'\0') {
+      break;
+    }
+
+    String++;
+  }
+
+  Index = ((UINTN)String - (UINTN)StringBak) / sizeof (CHAR16);
+  if (Index > CharMax - 1) {
+    Index = CharMax - 1;
+  }
+  StringBak[Index] = L'\0';
+
+  return EFI_SUCCESS;
+}
+
+/**
   Get volume and free space size information of an UDF volume.
 
   @attention This is boundary function that may receive untrusted input.
diff --git a/MdeModulePkg/Universal/Disk/UdfDxe/Udf.h b/MdeModulePkg/Universal/Disk/UdfDxe/Udf.h
index 9c3f21fd05..7eeaa6192c 100644
--- a/MdeModulePkg/Universal/Disk/UdfDxe/Udf.h
+++ b/MdeModulePkg/Universal/Disk/UdfDxe/Udf.h
@@ -900,6 +900,33 @@ SetFileInfo (
   );
 
 /**
+  Get volume label of an UDF volume.
+
+  @attention This is boundary function that may receive untrusted input.
+  @attention The input is from FileSystem.
+
+  The File Set Descriptor is external input, so this routine will do basic
+  validation for File Set Descriptor and report status.
+
+  @param[in]   Volume   Volume information pointer.
+  @param[in]   CharMax  The maximum number of Unicode char in String,
+                        including terminating null char.
+  @param[out]  String   String buffer pointer to store the volume label.
+
+  @retval EFI_SUCCESS           Volume label is returned.
+  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.
+  @retval EFI_BUFFER_TOO_SMALL  The string buffer String cannot hold the
+                                volume label.
+
+**/
+EFI_STATUS
+GetVolumeLabel (
+  IN   UDF_VOLUME_INFO  *Volume,
+  IN   UINTN            CharMax,
+  OUT  CHAR16           *String
+  );
+
+/**
   Get volume and free space size information of an UDF volume.
 
   @attention This is boundary function that may receive untrusted input.
diff --git a/MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf b/MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf
index c8bfc880ed..4f435140e9 100644
--- a/MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf
+++ b/MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf
@@ -58,6 +58,7 @@
 [Guids]
   gEfiFileInfoGuid                              ## SOMETIMES_CONSUMES ## Protocol
   gEfiFileSystemInfoGuid                        ## SOMETIMES_CONSUMES ## Protocol
+  gEfiFileSystemVolumeLabelInfoIdGuid           ## SOMETIMES_CONSUMES ## Protocol
 
 
 [Protocols]
-- 
2.12.0.windows.1



  parent reply	other threads:[~2018-10-16  7:23 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-16  7:23 [PATCH v1 00/10] UDF: Bugfixes Hao Wu
2018-10-16  7:23 ` [PATCH v1 01/10] MdeModulePkg/PartitionDxe: Add check for underlying device block size Hao Wu
2018-10-16  7:23 ` [PATCH v1 02/10] MdeModulePkg/UdfDxe: Refine boundary checks for file/path name string Hao Wu
2018-10-16  7:23 ` [PATCH v1 03/10] MdeModulePkg/UdfDxe: Add boundary check the read of FE/EFE Hao Wu
2018-10-16  7:23 ` [PATCH v1 04/10] MdeModulePkg/UdfDxe: Add boundary check for ComponentIdentifier decode Hao Wu
2018-10-16  7:23 ` [PATCH v1 05/10] MdeModulePkg/UdfDxe: Add boundary check for getting volume (free) size Hao Wu
2018-10-16  7:23 ` [PATCH v1 06/10] MdeModulePkg/UdfDxe: Correct behavior for UdfSetPosition() Hao Wu
2018-10-16  7:23 ` [PATCH v1 07/10] MdeModulePkg/UdfDxe: Fix a typo within SetFileInfo() Hao Wu
2018-10-16  7:23 ` Hao Wu [this message]
2018-10-16  7:23 ` [PATCH v1 09/10] MdeModulePkg/UdfDxe: Add more check when getting PD from LongAd Hao Wu
2018-10-16  7:23 ` [PATCH v1 10/10] MdeModulePkg/UdfDxe: Avoid possible use of already-freed data Hao Wu
2018-10-22 14:39 ` [PATCH v1 00/10] UDF: Bugfixes Paulo Alcantara
2018-10-23  5:45   ` Zeng, Star
2018-10-23  6:10     ` Wu, Hao A
2018-10-23 12:28       ` Wu, Hao A

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181016072340.22068-9-hao.a.wu@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox