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

Jeff Brasen posted 1 patch 3 years, 10 months ago
Failed in applying to current master (apply log)
There is a newer version of this series
.../Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c       | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[edk2-devel] [PATCH] MdeModulePkg/DxeCorePerformanceLib: Switch to UnicodeStrnToAsciiStrS
Posted by Jeff Brasen 3 years, 10 months 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       | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c b/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
index f500e20b32..89ae6fb964 100644
--- a/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
+++ b/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
@@ -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 (#60550): https://edk2.groups.io/g/devel/message/60550
Mute This Topic: https://groups.io/mt/74615004/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [PATCH] MdeModulePkg/DxeCorePerformanceLib: Switch to UnicodeStrnToAsciiStrS
Posted by Dandan Bi 3 years, 9 months ago
Thanks for the fix.
Could you also help update the UnicodeStrToAsciiStrS usage at line 840? Which potentially has the similar issue.
UnicodeStrToAsciiStrS(StringPtr, ComponentNameString, ControllerNameStringSize);


Thanks,
Dandan
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Jeff
> Brasen
> Sent: Tuesday, June 2, 2020 5:13 AM
> To: devel@edk2.groups.io
> Cc: Bi, Dandan <dandan.bi@intel.com>; Gao, Liming <liming.gao@intel.com>;
> Jeff Brasen <jbrasen@nvidia.com>
> Subject: [edk2-devel] [PATCH] 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       | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git
> a/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLi
> b.c
> b/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLi
> b.c
> index f500e20b32..89ae6fb964 100644
> ---
> a/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLi
> b.c
> +++
> b/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLi
> b.c
> @@ -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 (#61014): https://edk2.groups.io/g/devel/message/61014
Mute This Topic: https://groups.io/mt/74615004/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-