[edk2-devel] [PATCH v2] MdeModulePkg/DxeCorePerformanceLib: Switch to UnicodeStrnToAsciiStrS

Jeff Brasen posted 1 patch 2 weeks ago
Failed in applying to current master (apply log)
.../Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c     | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

[edk2-devel] [PATCH v2] MdeModulePkg/DxeCorePerformanceLib: Switch to UnicodeStrnToAsciiStrS

Posted by Jeff Brasen 2 weeks ago
UnicodeStrToAsciiStrS requires that the source string is shorter than
the destination buffer and will ASSERT if this is not true. Switch to
UnicodeStrnToAsciiStrS as there are cases where the source string is
longer than the buffer allocated for the device path.

Signed-off-by: Jeff Brasen <jbrasen@nvidia.com>
---
 .../Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c     | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c b/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
index f500e20b32..d378c59dd9 100644
--- a/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
+++ b/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
@@ -837,7 +837,7 @@ GetDeviceInfoFromHandleAndUpdateLength (
       ControllerNameStringSize = FPDT_MAX_PERF_RECORD_SIZE - (*Length) - 1;
     }
 
-    UnicodeStrToAsciiStrS(StringPtr, ComponentNameString, ControllerNameStringSize);
+    UnicodeStrnToAsciiStrS(StringPtr, ControllerNameStringSize - 1, ComponentNameString, ControllerNameStringSize, &ControllerNameStringSize);
 
     //
     // Add a space in the end of the ControllerName
@@ -879,7 +879,7 @@ GetDeviceInfoFromHandleAndUpdateLength (
         AsciiStringPtr = ComponentNameString;
       }
 
-      UnicodeStrToAsciiStrS(StringPtr, AsciiStringPtr, DevicePathStringSize);
+      UnicodeStrnToAsciiStrS(StringPtr, DevicePathStringSize - 1, AsciiStringPtr, DevicePathStringSize, &DevicePathStringSize);
       *Length += (UINT8)DevicePathStringSize;
       return EFI_SUCCESS;
     }
-- 
2.17.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#61566): https://edk2.groups.io/g/devel/message/61566
Mute This Topic: https://groups.io/mt/75044750/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [PATCH v2] MdeModulePkg/DxeCorePerformanceLib: Switch to UnicodeStrnToAsciiStrS

Posted by Dandan Bi 2 weeks ago
Reviewed-by: Dandan Bi <dandan.bi@intel.com>



Thanks,
Dandan
> -----Original Message-----
> From: Jeff Brasen <jbrasen@nvidia.com>
> Sent: Tuesday, June 23, 2020 2:20 AM
> To: devel@edk2.groups.io
> Cc: Gao, Liming <liming.gao@intel.com>; Bi, Dandan <dandan.bi@intel.com>;
> Jeff Brasen <jbrasen@nvidia.com>
> Subject: [PATCH v2] MdeModulePkg/DxeCorePerformanceLib: Switch to
> UnicodeStrnToAsciiStrS
> 
> UnicodeStrToAsciiStrS requires that the source string is shorter than the
> destination buffer and will ASSERT if this is not true. Switch to
> UnicodeStrnToAsciiStrS as there are cases where the source string is longer
> than the buffer allocated for the device path.
> 
> Signed-off-by: Jeff Brasen <jbrasen@nvidia.com>
> ---
>  .../Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c     | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git
> a/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLi
> b.c
> b/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLi
> b.c
> index f500e20b32..d378c59dd9 100644
> ---
> a/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLi
> b.c
> +++
> b/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLi
> b.c
> @@ -837,7 +837,7 @@ GetDeviceInfoFromHandleAndUpdateLength (
>        ControllerNameStringSize = FPDT_MAX_PERF_RECORD_SIZE - (*Length) -
> 1;
>      }
> 
> -    UnicodeStrToAsciiStrS(StringPtr, ComponentNameString,
> ControllerNameStringSize);
> +    UnicodeStrnToAsciiStrS(StringPtr, ControllerNameStringSize - 1,
> + ComponentNameString, ControllerNameStringSize,
> + &ControllerNameStringSize);
> 
>      //
>      // Add a space in the end of the ControllerName @@ -879,7 +879,7 @@
> GetDeviceInfoFromHandleAndUpdateLength (
>          AsciiStringPtr = ComponentNameString;
>        }
> 
> -      UnicodeStrToAsciiStrS(StringPtr, AsciiStringPtr, DevicePathStringSize);
> +      UnicodeStrnToAsciiStrS(StringPtr, DevicePathStringSize - 1,
> + AsciiStringPtr, DevicePathStringSize, &DevicePathStringSize);
>        *Length += (UINT8)DevicePathStringSize;
>        return EFI_SUCCESS;
>      }
> --
> 2.17.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#61626): https://edk2.groups.io/g/devel/message/61626
Mute This Topic: https://groups.io/mt/75044750/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-