]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/DxeNetLib: Rewrite NetblockChecksum function logic
authorHao Wu <hao.a.wu@intel.com>
Tue, 15 Nov 2016 07:39:44 +0000 (15:39 +0800)
committerHao Wu <hao.a.wu@intel.com>
Thu, 22 Dec 2016 08:17:19 +0000 (16:17 +0800)
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>
MdeModulePkg/Library/DxeNetLib/NetBuffer.c

index bbbdbc048aedc45acacc1b462f57e20d1beb69e1..95cb71714b5bbb3afdd748db3415e6f065809ee5 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Network library functions providing net buffer operation support.\r
 \r
-Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2005 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -1661,19 +1661,19 @@ NetblockChecksum (
 \r
   Sum = 0;\r
 \r
+  //\r
+  // Add left-over byte, if any\r
+  //\r
+  if (Len % 2 != 0) {\r
+    Sum += *(Bulk + Len - 1);\r
+  }\r
+\r
   while (Len > 1) {\r
     Sum += *(UINT16 *) Bulk;\r
     Bulk += 2;\r
     Len -= 2;\r
   }\r
 \r
-  //\r
-  // Add left-over byte, if any\r
-  //\r
-  if (Len > 0) {\r
-    Sum += *(UINT8 *) Bulk;\r
-  }\r
-\r
   //\r
   // Fold 32-bit sum to 16 bits\r
   //\r