public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] NetworkPkg: Correct the length of EAP Identity when in ASCII format
@ 2023-06-05  6:29 Li, Yi
  2023-06-16 19:07 ` [edk2-devel] " Clark-williams, Zachary
  0 siblings, 1 reply; 7+ messages in thread
From: Li, Yi @ 2023-06-05  6:29 UTC (permalink / raw)
  To: devel; +Cc: Yi Li, Maciej Rabeda, Siyuan Fu

FIX: https://bugzilla.tianocore.org/show_bug.cgi?id=4477

Tls connection fail over WiFi in AMT OCR flow due to invalid identity.

This was due to missing conversion between unicode and ascii
string which resulted in invalid strlen.

Cc: Maciej Rabeda <maciej.rabeda@linux.intel.com>
Cc: Siyuan Fu <siyuan.fu@intel.com>
Signed-off-by: Yi Li <yi1.li@intel.com>
---
 .../WifiConnectionMgrImpl.c                        | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.c b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.c
index 2e596c1981..e1430251c8 100644
--- a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.c
+++ b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.c
@@ -572,7 +572,14 @@ WifiMgrConfigEap (
   // Set Identity to Eap peer, Mandatory field for PEAP and TTLS
   //
   if (StrLen (Profile->EapIdentity) > 0) {
-    IdentitySize = sizeof (CHAR8) * (StrLen (Profile->EapIdentity) + 1);
+    Status = gBS->LocateProtocol (&gWiFiProfileSyncProtocolGuid, NULL, (VOID **) &WiFiProfileSyncProtocol);
+    if (!EFI_ERROR (Status) && WiFiProfileSyncProtocol != NULL) {
+      /* Max size of EapIdentity ::= sizeof (CHAR16) * sizeof (Profile->EapIdentity) ::= 2 * EAP_IDENTITY_SIZE */
+      IdentitySize = sizeof (CHAR8) * (AsciiStrnLenS ((CHAR8 *) Profile->EapIdentity, sizeof (CHAR16) * sizeof (Profile->EapIdentity)) + 1);
+    } else {
+      IdentitySize = sizeof (CHAR8) * (StrLen(Profile->EapIdentity) + 1);
+    }
+
     Identity     = AllocateZeroPool (IdentitySize);
     if (Identity == NULL) {
       return EFI_OUT_OF_RESOURCES;
@@ -580,7 +587,10 @@ WifiMgrConfigEap (
 
     Status = gBS->LocateProtocol (&gEdkiiWiFiProfileSyncProtocolGuid, NULL, (VOID **)&WiFiProfileSyncProtocol);
     if (!EFI_ERROR (Status)) {
-      CopyMem (Identity, &Profile->EapIdentity, IdentitySize);
+      /* The size of Identity from Username may equal
+         to the max size of EapIdentity(EAP_IDENTITY_SIZE*2=128 bytes),
+         so here only valid characters except NULL characters are copied. */
+      CopyMem (Identity, &Profile->EapIdentity, IdentitySize - 1);
     } else {
       UnicodeStrToAsciiStrS (Profile->EapIdentity, Identity, IdentitySize);
     }
-- 
2.31.1.windows.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread
[parent not found: <1765AF83686A77A3.7352@groups.io>]

end of thread, other threads:[~2023-06-27 18:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-05  6:29 [PATCH] NetworkPkg: Correct the length of EAP Identity when in ASCII format Li, Yi
2023-06-16 19:07 ` [edk2-devel] " Clark-williams, Zachary
2023-06-20  4:49   ` Li, Yi
2023-06-22 22:26     ` Clark-williams, Zachary
2023-06-26  8:36       ` Li, Yi
2023-06-27 18:07         ` Clark-williams, Zachary
     [not found] <1765AF83686A77A3.7352@groups.io>
2023-06-12  1:52 ` Li, Yi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox