Program: 5646
Project: 5646
Buggy source:
public void parsePacketData(IPv6Packet packet){
  int pos=2;
  int enc0=packet.getData(0);
  int enc1=packet.getData(1);
  if ((enc0 & 0x40) == 0) {
    if ((enc0 & 0x80) == 0) {
      packet.version=(packet.getData(pos) & 0xf0) >> 4;
      packet.trafficClass=((packet.getData(pos) & 0x0f) << 4) + ((packet.getData(pos + 1) & 0xff) >> 4);
      packet.flowLabel=(packet.getData(pos + 1) & 0x0f) << 16 + (packet.getData(pos + 2) & 0xff) << 8 + packet.getData(pos + 3) & 0xff;
      pos+=4;
    }
 else {
      packet.version=6;
      packet.trafficClass=0;
      packet.flowLabel=(packet.getData(pos) & 0x0f) << 16 + (packet.getData(pos + 1) & 0xff) << 8 + packet.getData(pos + 2) & 0xff;
      ;
      pos+=3;
    }
  }
 else {
    packet.version=6;
    packet.flowLabel=0;
    if ((enc0 & 0x80) == 0) {
      packet.trafficClass=(packet.getData(pos) & 0xff);
      pos++;
    }
 else {
      packet.trafficClass=0;
    }
  }
  if ((enc0 & 0x20) == 0) {
    packet.nextHeader=packet.getData(pos++);
  }
switch (enc0 & 0x18) {
case IPHC_TTL_1:
    packet.hopLimit=1;
  break;
case IPHC_TTL_64:
packet.hopLimit=64;
break;
case IPHC_TTL_255:
packet.hopLimit=0xff;
break;
case IPHC_TTL_I:
packet.hopLimit=packet.getData(pos++);
break;
}
int srcAddress=(packet.getData(1) & 0x30) >> 4;
AddrContext context=lookupContext(srcAddress);
switch (enc1 & 0xc0) {
case IPHC_SAM_0:
if (context == null) {
System.out.println("String_Node_Str");
return;
}
System.arraycopy(context.prefix,0,packet.sourceAddress,0,8);
byte[] linkAddress=packet.getLinkSource();
System.arraycopy(linkAddress,0,packet.sourceAddress,8,8);
packet.sourceAddress[8]^=0x02;
break;
case IPHC_SAM_16:
if ((packet.getData(pos) & 0x80) == 0) {
if (context == null) {
System.out.println("String_Node_Str");
return;
}
System.arraycopy(context.prefix,0,packet.sourceAddress,0,8);
java.util.Arrays.fill(packet.sourceAddress,8,14,(byte)0);
packet.sourceAddress[14]=packet.getData(pos);
packet.sourceAddress[15]=packet.getData(pos + 1);
pos+=2;
}
 else {
java.util.Arrays.fill(packet.sourceAddress,0,16,(byte)0);
packet.sourceAddress[0]=(byte)0xff;
packet.sourceAddress[1]=(byte)(((packet.getData(pos) & 0xff) >> 1) & 0x0f);
packet.sourceAddress[15]=packet.getData(pos + 1);
pos+=2;
}
break;
case IPHC_SAM_64:
if (context == null) {
System.out.println("String_Node_Str");
return;
}
System.arraycopy(context.prefix,0,packet.sourceAddress,0,8);
packet.copy(pos,packet.sourceAddress,8,8);
pos+=8;
break;
case IPHC_SAM_I:
packet.copy(pos,packet.sourceAddress,0,16);
pos+=16;
break;
}
context=lookupContext(packet.getData(2) & 0x03);
switch (enc1 & 0x0C) {
case IPHC_DAM_0:
if (context == null) {
System.out.println("String_Node_Str");
return;
}
System.arraycopy(context.prefix,0,packet.destAddress,0,8);
byte[] destAddress=packet.getLinkDestination();
System.arraycopy(destAddress,0,packet.destAddress,8,8);
packet.destAddress[8]^=0x02;
break;
case IPHC_DAM_16:
if ((packet.getData(pos) & 0x80) == 0) {
if (context == null) {
System.out.println("String_Node_Str");
return;
}
System.arraycopy(context.prefix,0,packet.destAddress,0,8);
packet.destAddress[14]=packet.getData(pos);
packet.destAddress[15]=packet.getData(pos + 1);
pos+=2;
}
 else {
System.out.println("String_Node_Str" + packet.getData(pos) + "String_Node_Str"+ packet.getData(pos + 1));
java.util.Arrays.fill(packet.destAddress,0,16,(byte)0);
packet.destAddress[0]=(byte)0xff;
packet.destAddress[1]=(byte)(((packet.getData(pos) & 0xff) >> 1) & 0x0F);
packet.destAddress[15]=(byte)(packet.getData(pos + 1) & 0xff);
pos+=2;
}
break;
case IPHC_DAM_64:
if (context == null) {
System.out.println("String_Node_Str");
return;
}
System.arraycopy(context.prefix,0,packet.destAddress,0,8);
packet.copy(pos,packet.destAddress,8,8);
pos+=8;
break;
case IPHC_DAM_I:
packet.copy(pos,packet.destAddress,0,16);
pos+=16;
break;
}
if ((enc0 & 0x20) != 0) {
if ((packet.getData(pos) & 0xfc) == NHC_UDP_ID) {
System.out.println("String_Node_Str");
packet.nextHeader=PROTO_UDP;
int srcPort=0;
int destPort=0;
int checkSum=0;
switch (packet.getData(pos) & 0xff) {
case NHC_UDP_C:
srcPort=UDP_PORT_MIN + ((packet.getData(pos + 1) & 0xff) >> 4);
destPort=UDP_PORT_MIN + (packet.getData(pos + 1) & 0x0F);
checkSum=((packet.getData(pos + 2) & 0xff) << 8) + (packet.getData(pos + 3) & 0xff);
pos+=4;
break;
case NHC_UDP_I:
srcPort=((packet.getData(pos + 1) & 0xff) << 8) + (packet.getData(pos + 2) & 0xff);
destPort=((packet.getData(pos + 3) & 0xff) << 8) + (packet.getData(pos + 4) & 0xff);
checkSum=((packet.getData(pos + 5) & 0xff) << 8) + (packet.getData(pos + 6) & 0xff);
pos+=7;
break;
default :
System.out.println("String_Node_Str");
return;
}
System.out.println("String_Node_Str" + destPort);
System.out.println("String_Node_Str" + srcPort);
System.out.println("String_Node_Str" + srcPort);
}
}
boolean frag=false;
if (!frag) {
packet.incPos(pos);
}
 else {
}
System.out.println("String_Node_Str" + Utils.hex8(enc0) + "String_Node_Str"+ Utils.hex8(enc1));
System.out.println("String_Node_Str" + packet.hopLimit);
System.out.print("String_Node_Str");
IPv6Packet.printAddress(System.out,packet.sourceAddress);
System.out.print("String_Node_Str");
IPv6Packet.printAddress(System.out,packet.destAddress);
System.out.println();
packet.payloadLen=packet.getPayloadLength();
}

Fixed version (ground truth):
public void parsePacketData(IPv6Packet packet){
  int pos=2;
  int enc1=packet.getData(0);
  int enc2=packet.getData(1);
  if ((enc1 & 0x40) == 0) {
    if ((enc1 & 0x80) == 0) {
      packet.version=(packet.getData(pos) & 0xf0) >> 4;
      packet.trafficClass=((packet.getData(pos) & 0x0f) << 4) + ((packet.getData(pos + 1) & 0xff) >> 4);
      packet.flowLabel=(packet.getData(pos + 1) & 0x0f) << 16 + (packet.getData(pos + 2) & 0xff) << 8 + packet.getData(pos + 3) & 0xff;
      pos+=4;
    }
 else {
      packet.version=6;
      packet.trafficClass=0;
      packet.flowLabel=(packet.getData(pos) & 0x0f) << 16 + (packet.getData(pos + 1) & 0xff) << 8 + packet.getData(pos + 2) & 0xff;
      ;
      pos+=3;
    }
  }
 else {
    packet.version=6;
    packet.flowLabel=0;
    if ((enc1 & 0x80) == 0) {
      packet.trafficClass=(packet.getData(pos) & 0xff);
      pos++;
    }
 else {
      packet.trafficClass=0;
    }
  }
  if ((enc1 & 0x20) == 0) {
    packet.nextHeader=packet.getData(pos++);
  }
switch (enc1 & 0x18) {
case IPHC_TTL_1:
    packet.hopLimit=1;
  break;
case IPHC_TTL_64:
packet.hopLimit=64;
break;
case IPHC_TTL_255:
packet.hopLimit=0xff;
break;
case IPHC_TTL_I:
packet.hopLimit=packet.getData(pos++);
break;
}
int srcAddress=(enc2 & 0x30) >> 4;
AddrContext context=lookupContext(srcAddress);
if (DEBUG) {
System.out.println("String_Node_Str" + (enc2 & 0xc0) + "String_Node_Str"+ srcAddress);
}
switch (enc2 & 0xc0) {
case IPHC_SAM_0:
if (context == null) {
System.out.println("String_Node_Str");
return;
}
System.arraycopy(context.prefix,0,packet.sourceAddress,0,8);
byte[] linkAddress=packet.getLinkSource();
System.arraycopy(linkAddress,0,packet.sourceAddress,8,8);
packet.sourceAddress[8]^=0x02;
break;
case IPHC_SAM_16:
if ((packet.getData(pos) & 0x80) == 0) {
if (context == null) {
System.out.println("String_Node_Str");
return;
}
System.arraycopy(context.prefix,0,packet.sourceAddress,0,8);
java.util.Arrays.fill(packet.sourceAddress,8,14,(byte)0);
packet.sourceAddress[14]=packet.getData(pos);
packet.sourceAddress[15]=packet.getData(pos + 1);
pos+=2;
}
 else {
java.util.Arrays.fill(packet.sourceAddress,0,16,(byte)0);
packet.sourceAddress[0]=(byte)0xff;
packet.sourceAddress[1]=(byte)(((packet.getData(pos) & 0xff) >> 1) & 0x0f);
packet.sourceAddress[15]=packet.getData(pos + 1);
pos+=2;
}
break;
case IPHC_SAM_64:
if (context == null) {
System.out.println("String_Node_Str");
return;
}
System.arraycopy(context.prefix,0,packet.sourceAddress,0,8);
packet.copy(pos,packet.sourceAddress,8,8);
pos+=8;
break;
case IPHC_SAM_I:
if (DEBUG) System.out.println("String_Node_Str");
packet.copy(pos,packet.sourceAddress,0,16);
pos+=16;
break;
}
context=lookupContext(enc2 & 0x03);
if (DEBUG) {
System.out.println("String_Node_Str" + (enc2 & 0x0c) + "String_Node_Str"+ (enc2 & 0x03));
}
switch (enc2 & 0x0C) {
case IPHC_DAM_0:
if (context == null) {
System.out.println("String_Node_Str");
return;
}
System.arraycopy(context.prefix,0,packet.destAddress,0,8);
byte[] destAddress=packet.getLinkDestination();
System.arraycopy(destAddress,0,packet.destAddress,8,8);
packet.destAddress[8]^=0x02;
break;
case IPHC_DAM_16:
if ((packet.getData(pos) & 0x80) == 0) {
if (context == null) {
System.out.println("String_Node_Str");
return;
}
System.arraycopy(context.prefix,0,packet.destAddress,0,8);
packet.destAddress[14]=packet.getData(pos);
packet.destAddress[15]=packet.getData(pos + 1);
pos+=2;
}
 else {
System.out.println("String_Node_Str" + packet.getData(pos) + "String_Node_Str"+ packet.getData(pos + 1));
java.util.Arrays.fill(packet.destAddress,0,16,(byte)0);
packet.destAddress[0]=(byte)0xff;
packet.destAddress[1]=(byte)(((packet.getData(pos) & 0xff) >> 1) & 0x0F);
packet.destAddress[15]=(byte)(packet.getData(pos + 1) & 0xff);
pos+=2;
}
break;
case IPHC_DAM_64:
if (context == null) {
System.out.println("String_Node_Str");
return;
}
System.arraycopy(context.prefix,0,packet.destAddress,0,8);
packet.copy(pos,packet.destAddress,8,8);
pos+=8;
break;
case IPHC_DAM_I:
packet.copy(pos,packet.destAddress,0,16);
pos+=16;
break;
}
if ((enc1 & 0x20) != 0) {
if ((packet.getData(pos) & 0xfc) == NHC_UDP_ID) {
System.out.println("String_Node_Str");
packet.nextHeader=PROTO_UDP;
int srcPort=0;
int destPort=0;
int checkSum=0;
switch (packet.getData(pos) & 0xff) {
case NHC_UDP_C:
srcPort=UDP_PORT_MIN + ((packet.getData(pos + 1) & 0xff) >> 4);
destPort=UDP_PORT_MIN + (packet.getData(pos + 1) & 0x0F);
checkSum=((packet.getData(pos + 2) & 0xff) << 8) + (packet.getData(pos + 3) & 0xff);
pos+=4;
break;
case NHC_UDP_I:
srcPort=((packet.getData(pos + 1) & 0xff) << 8) + (packet.getData(pos + 2) & 0xff);
destPort=((packet.getData(pos + 3) & 0xff) << 8) + (packet.getData(pos + 4) & 0xff);
checkSum=((packet.getData(pos + 5) & 0xff) << 8) + (packet.getData(pos + 6) & 0xff);
pos+=7;
break;
default :
System.out.println("String_Node_Str");
return;
}
System.out.println("String_Node_Str" + destPort);
System.out.println("String_Node_Str" + srcPort);
System.out.println("String_Node_Str" + srcPort);
}
}
boolean frag=false;
if (!frag) {
packet.incPos(pos);
}
 else {
}
System.out.println("String_Node_Str" + Utils.hex8(enc1) + "String_Node_Str"+ Utils.hex8(enc2));
System.out.println("String_Node_Str" + packet.hopLimit);
System.out.print("String_Node_Str");
IPv6Packet.printAddress(System.out,packet.sourceAddress);
System.out.print("String_Node_Str");
IPv6Packet.printAddress(System.out,packet.destAddress);
System.out.println();
packet.payloadLen=packet.getPayloadLength();
}