summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHao Wu <hao.a.wu@intel.com>2016-11-15 15:39:44 +0800
committerHao Wu <hao.a.wu@intel.com>2016-12-22 16:17:19 +0800
commit69e856dfa56cebfba1abf160f3c86458dde850d4 (patch)
treebadd62995c95b4e07371690295d624604ea1081c
parent9088c61e2d2de8c844f1850e6a96a69f81c0d010 (diff)
downloadedk2-platforms-69e856dfa56cebfba1abf160f3c86458dde850d4.tar.xz
MdeModulePkg/DxeNetLib: Rewrite NetblockChecksum function logic
This commit rewrites the logic for NetblockChecksum. It processes the checksum of the left-over byte first to prevent possible mis-reports by static code checkers. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Fu Siyuan <siyuan.fu@intel.com> Reviewed-by: Ye Ting <ting.ye@intel.com> Reviewed-by: Wu Jiaxin <jiaxin.wu@intel.com>
-rw-r--r--MdeModulePkg/Library/DxeNetLib/NetBuffer.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/MdeModulePkg/Library/DxeNetLib/NetBuffer.c b/MdeModulePkg/Library/DxeNetLib/NetBuffer.c
index bbbdbc048a..95cb71714b 100644
--- a/MdeModulePkg/Library/DxeNetLib/NetBuffer.c
+++ b/MdeModulePkg/Library/DxeNetLib/NetBuffer.c
@@ -1,7 +1,7 @@
/** @file
Network library functions providing net buffer operation support.
-Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -1661,6 +1661,13 @@ NetblockChecksum (
Sum = 0;
+ //
+ // Add left-over byte, if any
+ //
+ if (Len % 2 != 0) {
+ Sum += *(Bulk + Len - 1);
+ }
+
while (Len > 1) {
Sum += *(UINT16 *) Bulk;
Bulk += 2;
@@ -1668,13 +1675,6 @@ NetblockChecksum (
}
//
- // Add left-over byte, if any
- //
- if (Len > 0) {
- Sum += *(UINT8 *) Bulk;
- }
-
- //
// Fold 32-bit sum to 16 bits
//
while ((Sum >> 16) != 0) {