Fix NPE in ICMP.computeChecksum() 68/868/1
authorAlessandro Boch <aboch@cisco.com>
Wed, 14 Aug 2013 00:15:28 +0000 (17:15 -0700)
committerAlessandro Boch <aboch@cisco.com>
Wed, 14 Aug 2013 00:22:24 +0000 (17:22 -0700)
ISSUE:
ICMP.computeChecksum() incorrectly assumes rawPayload is always present
while determining the lenght of the ICMP packet byte stream on which
computing the checksum.

Change-Id: I41c1e0509f21a2bbb0a5ec6df038ed18a81f327a
Signed-off-by: Alessandro Boch <aboch@cisco.com>
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/ICMP.java

index 5075e58281132a4404ab8473be01e05ea5305115..b2a1cfe8c2824b8bfab8a4b737d949e9d67df446 100644 (file)
@@ -147,10 +147,11 @@ public class ICMP extends Packet {
     short computeChecksum(byte[] data, int start) {
         int sum = 0, carry = 0, finalSum = 0;
         int wordData;
     short computeChecksum(byte[] data, int start) {
         int sum = 0, carry = 0, finalSum = 0;
         int wordData;
-        int end = start + this.getHeaderSize() / NetUtils.NumBitsInAByte
-                + rawPayload.length;
-        int checksumStartByte = start + getfieldOffset(CHECKSUM)
-                / NetUtils.NumBitsInAByte;
+        int end = start + this.getHeaderSize() / NetUtils.NumBitsInAByte;
+        if (rawPayload != null) {
+            end += rawPayload.length;
+        }
+        int checksumStartByte = start + getfieldOffset(CHECKSUM) / NetUtils.NumBitsInAByte;
 
         for (int i = start; i <= (end - 1); i = i + 2) {
             // Skip, if the current bytes are checkSum bytes
 
         for (int i = start; i <= (end - 1); i = i + 2) {
             // Skip, if the current bytes are checkSum bytes