summaryrefslogtreecommitdiffstats
path: root/NetworkPkg
diff options
context:
space:
mode:
authordevel@edk2.groups.io <devel@edk2.groups.io>2023-06-25 22:40:34 -0700
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2023-06-28 02:56:39 +0000
commit4416bf3383485d2265b8e1baca7ed9c9c04eb40b (patch)
tree3c3e2ee5c25ee44339b6e53fbd742da6266f7dc4 /NetworkPkg
parent44a3d93af3fc3f3762d0e1f48137a370610dab2b (diff)
downloadedk2-4416bf3383485d2265b8e1baca7ed9c9c04eb40b.tar.gz
edk2-4416bf3383485d2265b8e1baca7ed9c9c04eb40b.tar.bz2
edk2-4416bf3383485d2265b8e1baca7ed9c9c04eb40b.zip
NetworkPkg: Correct the length of EAP Identity when in ASCII format
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: Zachary Clark-Williams <zachary.clark-williams@intel.com> Signed-off-by: Yi Li <yi1.li@intel.com> Reviewed-by: Zachary Clark-Williams <zachary.clark-williams@intel.com>
Diffstat (limited to 'NetworkPkg')
-rw-r--r--NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.c b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.c
index 2e596c1981..d1182e52bd 100644
--- a/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.c
+++ b/NetworkPkg/WifiConnectionManagerDxe/WifiConnectionMgrImpl.c
@@ -572,15 +572,28 @@ WifiMgrConfigEap (
// Set Identity to Eap peer, Mandatory field for PEAP and TTLS
//
if (StrLen (Profile->EapIdentity) > 0) {
- IdentitySize = sizeof (CHAR8) * (StrLen (Profile->EapIdentity) + 1);
- Identity = AllocateZeroPool (IdentitySize);
+ Status = gBS->LocateProtocol (&gEdkiiWiFiProfileSyncProtocolGuid, NULL, (VOID **)&WiFiProfileSyncProtocol);
+ if (!EFI_ERROR (Status)) {
+ //
+ // 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;
}
- 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);
}