Program: 5660
Project: 5660
Buggy source:
public void setPacketData(IPv6Packet packet,byte[] data,int len){
  int pos=2;
  if ((data[0] & 0x40) == 0) {
    if ((data[0] & 0x80) == 0) {
      packet.version=(data[pos] & 0xf0) >> 4;
      packet.trafficClass=((data[pos] & 0x0f) << 4) + ((data[pos + 1] & 0xff) >> 4);
      packet.flowLabel=(data[pos + 1] & 0x0f) << 16 + (data[pos + 2] & 0xff) << 8 + data[pos + 3] & 0xff;
      pos+=4;
    }
 else {
      packet.version=6;
      packet.trafficClass=0;
      packet.flowLabel=(data[pos] & 0x0f) << 16 + (data[pos + 1] & 0xff) << 8 + data[pos + 2] & 0xff;
      ;
      pos+=3;
    }
  }
 else {
    packet.version=6;
    packet.flowLabel=0;
    if ((data[0] & 0x80) == 0) {
      packet.trafficClass=(data[pos] & 0xff);
      pos++;
    }
 else {
      packet.trafficClass=0;
    }
  }
  if ((data[0] & 0x20) == 0) {
    packet.nextHeader=data[pos++];
  }
switch (data[0] & 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=data[pos++];
break;
}
int srcAddress=(data[1] & 0x30) >> 4;
AddrContext context=lookupContext(srcAddress);
switch (data[1] & 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=getLinkSourceAddress(packet);
System.arraycopy(linkAddress,0,packet.sourceAddress,8,8);
break;
case IPHC_SAM_16:
if ((data[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]=data[pos];
packet.sourceAddress[15]=data[pos + 1];
pos+=2;
}
 else {
java.util.Arrays.fill(packet.sourceAddress,0,16,(byte)0);
packet.sourceAddress[0]=(byte)0xff;
packet.sourceAddress[1]=(byte)(((data[pos] & 0xff) >> 1) & 0x0f);
packet.sourceAddress[15]=data[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);
System.arraycopy(data,pos,packet.sourceAddress,8,8);
pos+=8;
break;
case IPHC_SAM_I:
System.arraycopy(data,pos,packet.sourceAddress,0,16);
pos+=16;
break;
}
context=lookupContext(data[2] & 0x03);
switch (data[1] & 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=getLinkDestinationAddress(packet);
System.arraycopy(destAddress,0,packet.destAddress,8,8);
break;
case IPHC_DAM_16:
if ((data[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]=data[pos];
packet.destAddress[15]=data[pos + 1];
pos+=2;
}
 else {
System.out.println("String_Node_Str");
java.util.Arrays.fill(packet.destAddress,0,16,(byte)0);
packet.destAddress[0]=(byte)0xff;
packet.destAddress[1]=(byte)(((data[pos] & 0xff) >> 1) & 0x0F);
packet.destAddress[15]=data[pos + 1];
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);
System.arraycopy(data,pos,packet.destAddress,8,8);
pos+=8;
break;
case IPHC_DAM_I:
System.arraycopy(data,pos,packet.destAddress,0,16);
pos+=16;
break;
}
if ((data[0] & 0x20) != 0) {
if ((data[pos] & 0xfc) == NHC_UDP_ID) {
packet.nextHeader=PROTO_UDP;
int srcPort=0;
int destPort=0;
int checkSum=0;
switch (data[pos] & 0xff) {
case NHC_UDP_C:
srcPort=UDP_PORT_MIN + (data[pos + 1] >> 4);
destPort=UDP_PORT_MIN + (data[pos + 1] & 0x0F);
checkSum=(data[pos + 2] << 8) + data[pos + 3];
pos+=4;
break;
case NHC_UDP_I:
srcPort=((data[pos + 1] & 0xff) << 8) + (data[pos + 2] & 0xff);
destPort=((data[pos + 3] & 0xff) << 8) + (data[pos + 4] & 0xff);
checkSum=((data[pos + 5] & 0xff) << 8) + (data[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) {
int plen=len - pos;
packet.setPayload(data,pos,plen);
}
 else {
}
System.out.println("String_Node_Str" + Utils.hex8(data[0]) + "String_Node_Str"+ Utils.hex8(data[1]));
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();
}

Fixed version (ground truth):
public void setPacketData(IPv6Packet packet,byte[] data,int len){
  int pos=2;
  if ((data[0] & 0x40) == 0) {
    if ((data[0] & 0x80) == 0) {
      packet.version=(data[pos] & 0xf0) >> 4;
      packet.trafficClass=((data[pos] & 0x0f) << 4) + ((data[pos + 1] & 0xff) >> 4);
      packet.flowLabel=(data[pos + 1] & 0x0f) << 16 + (data[pos + 2] & 0xff) << 8 + data[pos + 3] & 0xff;
      pos+=4;
    }
 else {
      packet.version=6;
      packet.trafficClass=0;
      packet.flowLabel=(data[pos] & 0x0f) << 16 + (data[pos + 1] & 0xff) << 8 + data[pos + 2] & 0xff;
      ;
      pos+=3;
    }
  }
 else {
    packet.version=6;
    packet.flowLabel=0;
    if ((data[0] & 0x80) == 0) {
      packet.trafficClass=(data[pos] & 0xff);
      pos++;
    }
 else {
      packet.trafficClass=0;
    }
  }
  if ((data[0] & 0x20) == 0) {
    packet.nextHeader=data[pos++];
  }
switch (data[0] & 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=data[pos++];
break;
}
int srcAddress=(data[1] & 0x30) >> 4;
AddrContext context=lookupContext(srcAddress);
switch (data[1] & 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=getLinkSourceAddress(packet);
System.arraycopy(linkAddress,0,packet.sourceAddress,8,8);
break;
case IPHC_SAM_16:
if ((data[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]=data[pos];
packet.sourceAddress[15]=data[pos + 1];
pos+=2;
}
 else {
java.util.Arrays.fill(packet.sourceAddress,0,16,(byte)0);
packet.sourceAddress[0]=(byte)0xff;
packet.sourceAddress[1]=(byte)(((data[pos] & 0xff) >> 1) & 0x0f);
packet.sourceAddress[15]=data[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);
System.arraycopy(data,pos,packet.sourceAddress,8,8);
pos+=8;
break;
case IPHC_SAM_I:
System.arraycopy(data,pos,packet.sourceAddress,0,16);
pos+=16;
break;
}
context=lookupContext(data[2] & 0x03);
switch (data[1] & 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=getLinkDestinationAddress(packet);
System.arraycopy(destAddress,0,packet.destAddress,8,8);
break;
case IPHC_DAM_16:
if ((data[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]=data[pos];
packet.destAddress[15]=data[pos + 1];
pos+=2;
}
 else {
System.out.println("String_Node_Str");
java.util.Arrays.fill(packet.destAddress,0,16,(byte)0);
packet.destAddress[0]=(byte)0xff;
packet.destAddress[1]=(byte)(((data[pos] & 0xff) >> 1) & 0x0F);
packet.destAddress[15]=data[pos + 1];
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);
System.arraycopy(data,pos,packet.destAddress,8,8);
pos+=8;
break;
case IPHC_DAM_I:
System.arraycopy(data,pos,packet.destAddress,0,16);
pos+=16;
break;
}
if ((data[0] & 0x20) != 0) {
if ((data[pos] & 0xfc) == NHC_UDP_ID) {
packet.nextHeader=PROTO_UDP;
int srcPort=0;
int destPort=0;
int checkSum=0;
switch (data[pos] & 0xff) {
case NHC_UDP_C:
srcPort=UDP_PORT_MIN + ((data[pos + 1] & 0xff) >> 4);
destPort=UDP_PORT_MIN + (data[pos + 1] & 0x0F);
checkSum=((data[pos + 2] & 0xff) << 8) + (data[pos + 3] & 0xff);
pos+=4;
break;
case NHC_UDP_I:
srcPort=((data[pos + 1] & 0xff) << 8) + (data[pos + 2] & 0xff);
destPort=((data[pos + 3] & 0xff) << 8) + (data[pos + 4] & 0xff);
checkSum=((data[pos + 5] & 0xff) << 8) + (data[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) {
int plen=len - pos;
packet.setPayload(data,pos,plen);
}
 else {
}
System.out.println("String_Node_Str" + Utils.hex8(data[0]) + "String_Node_Str"+ Utils.hex8(data[1]));
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();
}