Program: 25464
Project: 25464
Buggy source:
/** 
 * process an OFPacketOut message to verify that it fits in this slice properly.  We don't want one slice to be able to inject traffic into another slice erroneously
 * @param output the OFPacketOut message to be properly sliced
 */
public List<OFMessage> allowedPacketOut(OFPacketOut outPacket){
  List<OFAction> newActions=new ArrayList<OFAction>();
  List<OFAction> actions=outPacket.getActions();
  List<OFMessage> packets=new ArrayList<OFMessage>();
  Iterator<OFAction> it=actions.iterator();
  OFMatch match=new OFMatch();
  if (outPacket.getPacketData().length == 0 && outPacket.getBufferId() != 0) {
    int bufferId=outPacket.getBufferId();
    if (this.bufferIds.containsKey(bufferId)) {
      outPacket.setBufferId(OFPacketOut.BUFFER_ID_NONE);
      outPacket.setPacketData(this.bufferIds.get(bufferId));
      outPacket.setLengthU(outPacket.getLengthU() + this.bufferIds.get(bufferId).length);
    }
 else {
      return packets;
    }
  }
  try {
    match.loadFromPacket(outPacket.getPacketData(),(short)0);
  }
 catch (  Exception e) {
    log.error("String_Node_Str" + e.getMessage());
    packets.clear();
    return packets;
  }
  short curVlan=match.getDataLayerVirtualLan();
  while (it.hasNext()) {
    OFAction action=it.next();
switch (action.getType()) {
case SET_VLAN_ID:
      OFActionVirtualLanIdentifier setvid=(OFActionVirtualLanIdentifier)action;
    curVlan=setvid.getVirtualLanIdentifier();
  newActions.add(action);
break;
case OUTPUT:
OFActionOutput output=(OFActionOutput)action;
if (output.getPort() == OFPort.OFPP_ALL.getValue()) {
log.info("String_Node_Str");
for (Map.Entry<String,PortConfig> port : this.portList.entrySet()) {
PortConfig myPortCfg=this.getPortConfig(port.getValue().getPortId());
if (myPortCfg == null) {
  log.info("String_Node_Str" + port.getValue().getPortId());
  packets.clear();
  return packets;
}
if (!myPortCfg.vlanAllowed(curVlan)) {
  log.info("String_Node_Str" + port.getValue().getPortId() + "String_Node_Str"+ curVlan);
  packets.clear();
  return packets;
}
log.debug("String_Node_Str" + port.getValue().getPortId());
List<OFAction> actualActions=new ArrayList<OFAction>();
actualActions.addAll(newActions);
OFPacketOut newOut=this.clonePacketOut(outPacket);
OFActionOutput newOutput=new OFActionOutput();
newOutput.setMaxLength(Short.MAX_VALUE);
newOutput.setType(OFActionType.OUTPUT);
newOutput.setLength((short)OFActionOutput.MINIMUM_LENGTH);
newOutput.setPort(port.getValue().getPortId());
actualActions.add(newOutput);
newOut.setActions(actualActions);
int size=0;
for (OFAction act : actualActions) {
  size=size + act.getLengthU();
}
newOut.setActionsLength((short)size);
packets.add(newOut);
}
}
 else if (output.getPort() == OFPort.OFPP_FLOOD.getValue()) {
log.info("String_Node_Str");
packets.clear();
return packets;
}
 else {
PortConfig myPortCfg=this.getPortConfig(output.getPort());
if (myPortCfg == null) {
log.info("String_Node_Str" + output.getPort());
packets.clear();
return packets;
}
if (!myPortCfg.vlanAllowed(curVlan)) {
log.info("String_Node_Str" + output.getPort() + "String_Node_Str"+ curVlan);
packets.clear();
return packets;
}
log.debug("String_Node_Str");
List<OFAction> actualActions=new ArrayList<OFAction>();
actualActions.addAll(newActions);
OFPacketOut newOut=this.clonePacketOut(outPacket);
actualActions.add(output);
newOut.setActions(actualActions);
int size=0;
for (OFAction act : actualActions) {
size=size + act.getLengthU();
}
newOut.setActionsLength((short)size);
packets.add(newOut);
}
break;
case STRIP_VLAN:
curVlan=0;
newActions.add(action);
break;
default :
newActions.add(action);
break;
}
}
log.debug("String_Node_Str" + packets.toString());
return packets;
}

Fixed version (ground truth):
/** 
 * process an OFPacketOut message to verify that it fits in this slice properly.  We don't want one slice to be able to inject traffic into another slice erroneously
 * @param output the OFPacketOut message to be properly sliced
 */
public List<OFMessage> allowedPacketOut(OFPacketOut outPacket){
  List<OFAction> newActions=new ArrayList<OFAction>();
  List<OFAction> actions=outPacket.getActions();
  List<OFMessage> packets=new ArrayList<OFMessage>();
  Iterator<OFAction> it=actions.iterator();
  OFMatch match=new OFMatch();
  if (outPacket.getPacketData().length == 0 && outPacket.getBufferId() != 0) {
    int bufferId=outPacket.getBufferId();
    if (this.bufferIds.containsKey(bufferId)) {
      outPacket.setBufferId(OFPacketOut.BUFFER_ID_NONE);
      outPacket.setPacketData(this.bufferIds.get(bufferId));
      outPacket.setLengthU(outPacket.getLengthU() + this.bufferIds.get(bufferId).length);
    }
 else {
      return packets;
    }
  }
  try {
    match.loadFromPacket(outPacket.getPacketData(),(short)0);
  }
 catch (  Exception e) {
    log.error("String_Node_Str" + e.getMessage());
    packets.clear();
    return packets;
  }
  short curVlan=match.getDataLayerVirtualLan();
  while (it.hasNext()) {
    OFAction action=it.next();
switch (action.getType()) {
case SET_VLAN_ID:
      OFActionVirtualLanIdentifier setvid=(OFActionVirtualLanIdentifier)action;
    curVlan=setvid.getVirtualLanIdentifier();
  newActions.add(action);
break;
case OUTPUT:
OFActionOutput output=(OFActionOutput)action;
if (output.getPort() == OFPort.OFPP_ALL.getValue()) {
log.info("String_Node_Str");
for (Map.Entry<String,PortConfig> port : this.portList.entrySet()) {
PortConfig myPortCfg=this.getPortConfig(port.getValue().getPortId());
if (myPortCfg == null) {
  log.info("String_Node_Str" + port.getValue().getPortId());
  packets.clear();
  return packets;
}
if (!myPortCfg.vlanAllowed(curVlan)) {
  log.info("String_Node_Str" + port.getValue().getPortId() + "String_Node_Str"+ curVlan);
  packets.clear();
  return packets;
}
log.debug("String_Node_Str" + port.getValue().getPortId());
List<OFAction> actualActions=new ArrayList<OFAction>();
actualActions.addAll(newActions);
OFPacketOut newOut=this.clonePacketOut(outPacket);
OFActionOutput newOutput=new OFActionOutput();
newOutput.setMaxLength(Short.MAX_VALUE);
newOutput.setType(OFActionType.OUTPUT);
newOutput.setLength((short)OFActionOutput.MINIMUM_LENGTH);
newOutput.setPort(port.getValue().getPortId());
actualActions.add(newOutput);
newOut.setActions(actualActions);
int size=0;
for (OFAction act : actualActions) {
  size=size + act.getLengthU();
}
newOut.setActionsLength((short)size);
newOut.setLength((short)(OFPacketOut.MINIMUM_LENGTH + newOut.getPacketData().length + size));
packets.add(newOut);
}
}
 else if (output.getPort() == OFPort.OFPP_FLOOD.getValue()) {
log.info("String_Node_Str");
packets.clear();
return packets;
}
 else {
PortConfig myPortCfg=this.getPortConfig(output.getPort());
if (myPortCfg == null) {
log.info("String_Node_Str" + output.getPort());
packets.clear();
return packets;
}
if (!myPortCfg.vlanAllowed(curVlan)) {
log.info("String_Node_Str" + output.getPort() + "String_Node_Str"+ curVlan);
packets.clear();
return packets;
}
log.debug("String_Node_Str");
List<OFAction> actualActions=new ArrayList<OFAction>();
actualActions.addAll(newActions);
OFPacketOut newOut=this.clonePacketOut(outPacket);
actualActions.add(output);
newOut.setActions(actualActions);
int size=0;
for (OFAction act : actualActions) {
size=size + act.getLengthU();
}
newOut.setActionsLength((short)size);
newOut.setLength((short)(OFPacketOut.MINIMUM_LENGTH + newOut.getPacketData().length + size));
packets.add(newOut);
}
break;
case STRIP_VLAN:
curVlan=0;
newActions.add(action);
break;
default :
newActions.add(action);
break;
}
}
log.debug("String_Node_Str" + packets.toString());
return packets;
}