Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3668)

Move the check to see if the RNGAlgorithmList pointer is NULL to
ArchGetSupportedRngAlgorithms(). This allows the caller to obtain
the buffer size required to store the Algorithm List by passing
RNGAlgorithmListSize as zero and RNGAlgorithmList as NULL.

Signed-off-by: Sami Mujawar <sami.muja...@arm.com>
---

Notes:
    v2:
     - No code change since v1. Re-sending with V2 series.   [SAMI]

 SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c     |  6 ++++++
 SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c          | 11 ++---------
 SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h |  2 +-
 3 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c 
b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c
index 
2009f95b4cadb07fc9073c3c0660cf549965422a..f1122a48102595506cc423c3ab501d9a72f50543
 100644
--- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c
+++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c
@@ -16,6 +16,7 @@
 
   Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
   (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
+  Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -116,6 +117,7 @@ RngGetRNG (
 
   @retval EFI_SUCCESS                 The RNG algorithm list was returned 
successfully.
   @retval EFI_BUFFER_TOO_SMALL        The buffer RNGAlgorithmList is too small 
to hold the result.
+  @retval EFI_INVALID_PARAMETER       The pointer to the buffer 
RNGAlgorithmList is invalid.
 
 **/
 UINTN
@@ -135,6 +137,10 @@ ArchGetSupportedRngAlgorithms (
     return EFI_BUFFER_TOO_SMALL;
   }
 
+  if (RNGAlgorithmList == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
   CpuRngSupportedAlgorithm = PcdGetPtr (PcdCpuRngSupportedAlgorithm);
 
   CopyMem(&RNGAlgorithmList[0], CpuRngSupportedAlgorithm, sizeof 
(EFI_RNG_ALGORITHM));
diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c 
b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c
index 
b959c70536ea3b9049905bbfd3d973fc9b2f6dcf..2e3b714bc691e4e517866369c034b721fbccfa24
 100644
--- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c
+++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c
@@ -14,6 +14,7 @@
 
 Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
 (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
+  Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
 
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -59,8 +60,6 @@ RngGetInfo (
   OUT EFI_RNG_ALGORITHM           *RNGAlgorithmList
   )
 {
-  EFI_STATUS    Status;
-
   if ((This == NULL) || (RNGAlgorithmListSize == NULL)) {
     return EFI_INVALID_PARAMETER;
   }
@@ -68,13 +67,7 @@ RngGetInfo (
   //
   // Return algorithm list supported by driver.
   //
-  if (RNGAlgorithmList != NULL) {
-    Status = ArchGetSupportedRngAlgorithms (RNGAlgorithmListSize, 
RNGAlgorithmList);
-  } else {
-    Status = EFI_INVALID_PARAMETER;
-  }
-
-  return Status;
+  return ArchGetSupportedRngAlgorithms (RNGAlgorithmListSize, 
RNGAlgorithmList);
 }
 
 //
diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h 
b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h
index 
34886adcf549efdedc1a7b8f16b81a5148531de2..37c27c4094e5302dfe2e7d9bbeef33a24b0c73ea
 100644
--- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h
+++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h
@@ -90,7 +90,7 @@ RngGetRNG (
 
   @retval EFI_SUCCESS                 The RNG algorithm list was returned 
successfully.
   @retval EFI_BUFFER_TOO_SMALL        The buffer RNGAlgorithmList is too small 
to hold the result.
-
+  @retval EFI_INVALID_PARAMETER       The pointer to the buffer 
RNGAlgorithmList is invalid.
 **/
 UINTN
 EFIAPI
-- 
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#83781): https://edk2.groups.io/g/devel/message/83781
Mute This Topic: https://groups.io/mt/87092741/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to