NetworkPkg/DxeNetLib: Fix unaligned access in NetblockChecksum

Into this routine the caller passes different data structures with
different alignment that is why casting bulk pointer to UINT16 violates
strict aliasing rule.
This commit is contained in:
Savva Mitrofanov 2025-03-07 15:47:24 +03:00 committed by Mikhail Krichanov
parent 2068113e8b
commit ee37e305bd

View File

@ -1618,20 +1618,12 @@ NetblockChecksum (
)
{
register UINT32 Sum;
UINT32 BulkPtr;
Sum = 0;
//
// Add left-over byte, if any
//
if (Len % 2 != 0) {
Sum += *(Bulk + Len - 1);
}
while (Len > 1) {
Sum += *(UINT16 *)Bulk;
Bulk += 2;
Len -= 2;
for (BulkPtr = 0; BulkPtr < Len; BulkPtr++, Bulk++) {
Sum += ((*Bulk) << ((BulkPtr & 1U) * 8U));
}
//