]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/SnpDxe/Nvdata.c
Refine soma code to make code run safely.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / Nvdata.c
index 4b9259f87a0d48bb51155504e085e5a7ba508e13..443979087e59c56ea87b7ae34df1c7d6a4b7c279 100644 (file)
@@ -1,9 +1,9 @@
 /** @file\r
-               Implementation of reading and writing operations on the NVRAM device\r
-               attached to a network interface.\r
+       Implementation of reading and writing operations on the NVRAM device\r
+       attached to a network interface.\r
  \r
-Copyright (c) 2004 - 2007, Intel Corporation. <BR> \r
-All rights reserved. This program and the accompanying materials are licensed \r
+Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials are licensed \r
 and made available under the terms and conditions of the BSD License which \r
 accompanies this distribution. The full text of the license may be found at \r
 http://opensource.org/licenses/bsd-license.php \r
@@ -24,6 +24,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
   @param  BufferSize   number of bytes to read\r
   @param  Buffer       pointer where to read into\r
 \r
+  @retval EFI_SUCCESS           The NVRAM access was performed.\r
+  @retval EFI_INVALID_PARAMETER Invalid UNDI command.\r
+  @retval EFI_UNSUPPORTED       Command is not supported by UNDI.\r
+  @retval EFI_DEVICE_ERROR      Fail to execute UNDI command.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -44,7 +48,7 @@ PxeNvDataRead (
   Snp->Cdb.CPBsize    = PXE_CPBSIZE_NOT_USED;\r
   Snp->Cdb.CPBaddr    = PXE_CPBADDR_NOT_USED;\r
 \r
-  Snp->Cdb.DBsize     = sizeof (PXE_DB_NVDATA);\r
+  Snp->Cdb.DBsize     = (UINT16) sizeof (PXE_DB_NVDATA);\r
   Snp->Cdb.DBaddr     = (UINT64)(UINTN) Db;\r
 \r
   Snp->Cdb.StatCode   = PXE_STATCODE_INITIALIZE;\r
@@ -84,7 +88,9 @@ PxeNvDataRead (
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
-  CopyMem (Buffer, Db->Data.Byte + Offset, BufferSize);\r
+  ASSERT (Offset < sizeof (Db->Data));\r
+\r
+  CopyMem (Buffer, &Db->Data.Byte[Offset], BufferSize);\r
 \r
   return EFI_SUCCESS;\r
 }\r