From 92d65efa7b1f42cc0f24546c3b33c28159197176 Mon Sep 17 00:00:00 2001 From: Alessandro Boch Date: Tue, 13 Aug 2013 17:15:28 -0700 Subject: [PATCH 1/1] Fix NPE in ICMP.computeChecksum() 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 --- .../org/opendaylight/controller/sal/packet/ICMP.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/ICMP.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/ICMP.java index 5075e58281..b2a1cfe8c2 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/ICMP.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/ICMP.java @@ -147,10 +147,11 @@ public class ICMP extends Packet { 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 -- 2.36.6