Program: 32233
Project: 32233
Buggy source:
/** 
 * This will send the received packet to the registered service. It will default to the single registered "foreground" app. This can be overridden to provide more specific functionality. 
 * @param packet the packet that is received
 * @return whether or not the sending was successful 
 */
public boolean sendPacketToRegisteredApp(SdlPacket packet){
  if (registeredApps != null && (registeredApps.size() > 0)) {
    int session=packet.getSessionId();
    boolean shouldAssertNewSession=packet.getFrameType() == FrameType.Control && (packet.getFrameInfo() == SdlPacket.FRAME_INFO_START_SERVICE_ACK || packet.getFrameInfo() == SdlPacket.FRAME_INFO_START_SERVICE_NAK);
    String appid=getAppIDForSession(session,shouldAssertNewSession);
    if (appid != null && appid.length() > 0) {
      RegisteredApp app;
synchronized (REGISTERED_APPS_LOCK) {
        app=registeredApps.get(appid);
      }
      if (app == null) {
        Log.e(TAG,"String_Node_Str" + appid + "String_Node_Str");
        removeSessionFromMap(session);
        byte[] uai=createForceUnregisterApp((byte)session,(byte)packet.getVersion());
        manuallyWriteBytes(uai,0,uai.length);
        int hashId=0;
synchronized (this.SESSION_LOCK) {
          if (this.sessionHashIdMap.indexOfKey(session) >= 0) {
            hashId=this.sessionHashIdMap.get(session);
            this.sessionHashIdMap.delete(session);
          }
        }
        byte[] stopService=(SdlPacketFactory.createEndSession(SessionType.RPC,(byte)session,0,(byte)packet.getVersion(),BitConverter.intToByteArray(hashId))).constructPacket();
        manuallyWriteBytes(stopService,0,stopService.length);
        return false;
      }
      byte version=(byte)packet.getVersion();
      if (shouldAssertNewSession && version > 1 && packet.getFrameInfo() == SdlPacket.FRAME_INFO_START_SERVICE_ACK) {
        if (packet.getPayload() != null && packet.getDataSize() == 4) {
synchronized (SESSION_LOCK) {
            this.sessionHashIdMap.put(session,(BitConverter.intFromByteArray(packet.getPayload(),0)));
          }
        }
      }
      int packetSize=(int)(packet.getDataSize() + SdlPacket.HEADER_SIZE);
      Message message=Message.obtain();
      Bundle bundle=new Bundle();
      if (packetSize < ByteArrayMessageSpliter.MAX_BINDER_SIZE) {
        message.what=TransportConstants.ROUTER_RECEIVED_PACKET;
        bundle.putParcelable(FORMED_PACKET_EXTRA_NAME,packet);
        bundle.putInt(TransportConstants.BYTES_TO_SEND_FLAGS,TransportConstants.BYTES_TO_SEND_FLAG_NONE);
        message.setData(bundle);
        return sendPacketMessageToClient(app,message,version);
      }
 else {
        byte[] bytes=packet.getPayload();
        SdlPacket copyPacket=new SdlPacket(packet.getVersion(),packet.isEncrypted(),(int)packet.getFrameType().getValue(),packet.getServiceType(),packet.getFrameInfo(),session,(int)packet.getDataSize(),packet.getMessageId(),null);
        message.what=TransportConstants.ROUTER_RECEIVED_PACKET;
        bundle.putParcelable(FORMED_PACKET_EXTRA_NAME,copyPacket);
        bundle.putInt(TransportConstants.BYTES_TO_SEND_FLAGS,TransportConstants.BYTES_TO_SEND_FLAG_SDL_PACKET_INCLUDED);
        message.setData(bundle);
        if (!sendPacketMessageToClient(app,message,version)) {
          Log.w(TAG,"String_Node_Str" + app.appId);
          return false;
        }
        ByteArrayMessageSpliter splitter=new ByteArrayMessageSpliter(appid,TransportConstants.ROUTER_RECEIVED_PACKET,bytes,0);
        while (splitter.isActive()) {
          if (!sendPacketMessageToClient(app,splitter.nextMessage(),version)) {
            Log.w(TAG,"String_Node_Str" + app.appId);
            splitter.close();
            return false;
          }
        }
      }
    }
 else {
      Log.e(TAG,"String_Node_Str");
      if (removeSessionFromMap(session)) {
        Log.i(TAG,"String_Node_Str");
        attemptToCleanUpModule(session,packet.getVersion());
      }
 else {
        if (packet.getFrameType() == FrameType.Single && packet.getServiceType() == SdlPacket.SERVICE_TYPE_RPC) {
          BinaryFrameHeader binFrameHeader=BinaryFrameHeader.parseBinaryHeader(packet.getPayload());
          if (binFrameHeader != null && FunctionID.UNREGISTER_APP_INTERFACE.getId() == binFrameHeader.getFunctionID()) {
            Log.d(TAG,"String_Node_Str");
          }
 else {
            attemptToCleanUpModule(session,packet.getVersion());
          }
        }
 else         if ((packet.getFrameType() == FrameType.Control && (packet.getFrameInfo() == SdlPacket.FRAME_INFO_END_SERVICE_ACK || packet.getFrameInfo() == SdlPacket.FRAME_INFO_END_SERVICE_NAK))) {
          Log.d(TAG,"String_Node_Str");
        }
 else {
          attemptToCleanUpModule(session,packet.getVersion());
        }
      }
    }
  }
  return false;
}

Fixed version (ground truth):
/** 
 * This will send the received packet to the registered service. It will default to the single registered "foreground" app. This can be overridden to provide more specific functionality. 
 * @param packet the packet that is received
 * @return whether or not the sending was successful 
 */
public boolean sendPacketToRegisteredApp(SdlPacket packet){
  if (registeredApps != null && (registeredApps.size() > 0)) {
    int session=packet.getSessionId();
    boolean shouldAssertNewSession=packet.getFrameType() == FrameType.Control && (packet.getFrameInfo() == SdlPacket.FRAME_INFO_START_SERVICE_ACK || packet.getFrameInfo() == SdlPacket.FRAME_INFO_START_SERVICE_NAK);
    String appid=getAppIDForSession(session,shouldAssertNewSession);
    if (appid != null && appid.length() > 0) {
      RegisteredApp app;
synchronized (REGISTERED_APPS_LOCK) {
        app=registeredApps.get(appid);
      }
      if (app == null) {
        Log.e(TAG,"String_Node_Str" + appid + "String_Node_Str");
        removeSessionFromMap(session);
        byte[] uai=createForceUnregisterApp((byte)session,(byte)packet.getVersion());
        manuallyWriteBytes(uai,0,uai.length);
        int hashId=0;
synchronized (this.SESSION_LOCK) {
          if (this.sessionHashIdMap.indexOfKey(session) >= 0) {
            hashId=this.sessionHashIdMap.get(session);
            this.sessionHashIdMap.delete(session);
          }
        }
        byte[] stopService=(SdlPacketFactory.createEndSession(SessionType.RPC,(byte)session,0,(byte)packet.getVersion(),BitConverter.intToByteArray(hashId))).constructPacket();
        manuallyWriteBytes(stopService,0,stopService.length);
        return false;
      }
      byte version=(byte)packet.getVersion();
      if (shouldAssertNewSession && version > 1 && packet.getFrameInfo() == SdlPacket.FRAME_INFO_START_SERVICE_ACK) {
        if (packet.getPayload() != null && packet.getDataSize() == 4) {
synchronized (SESSION_LOCK) {
            this.sessionHashIdMap.put(session,(BitConverter.intFromByteArray(packet.getPayload(),0)));
          }
        }
      }
      if (cleanedSessionMap != null && cleanedSessionMap.size() > 0) {
        if (packet.getFrameType() == FrameType.Single && packet.getServiceType() == SdlPacket.SERVICE_TYPE_RPC) {
          BinaryFrameHeader binFrameHeader=BinaryFrameHeader.parseBinaryHeader(packet.getPayload());
          if (binFrameHeader != null && FunctionID.UNREGISTER_APP_INTERFACE.getId() == binFrameHeader.getFunctionID()) {
            Log.d(TAG,"String_Node_Str");
            int hashOfRemoved=this.cleanedSessionMap.get(session,-1);
            int currentHash=this.sessionHashIdMap.get(session,-1);
            if (hashOfRemoved != -1) {
              if (hashOfRemoved != currentHash) {
                Log.d(TAG,"String_Node_Str");
                this.cleanedSessionMap.delete(session);
                return false;
              }
            }
          }
        }
      }
      int packetSize=(int)(packet.getDataSize() + SdlPacket.HEADER_SIZE);
      Message message=Message.obtain();
      Bundle bundle=new Bundle();
      if (packetSize < ByteArrayMessageSpliter.MAX_BINDER_SIZE) {
        message.what=TransportConstants.ROUTER_RECEIVED_PACKET;
        bundle.putParcelable(FORMED_PACKET_EXTRA_NAME,packet);
        bundle.putInt(TransportConstants.BYTES_TO_SEND_FLAGS,TransportConstants.BYTES_TO_SEND_FLAG_NONE);
        message.setData(bundle);
        return sendPacketMessageToClient(app,message,version);
      }
 else {
        byte[] bytes=packet.getPayload();
        SdlPacket copyPacket=new SdlPacket(packet.getVersion(),packet.isEncrypted(),(int)packet.getFrameType().getValue(),packet.getServiceType(),packet.getFrameInfo(),session,(int)packet.getDataSize(),packet.getMessageId(),null);
        message.what=TransportConstants.ROUTER_RECEIVED_PACKET;
        bundle.putParcelable(FORMED_PACKET_EXTRA_NAME,copyPacket);
        bundle.putInt(TransportConstants.BYTES_TO_SEND_FLAGS,TransportConstants.BYTES_TO_SEND_FLAG_SDL_PACKET_INCLUDED);
        message.setData(bundle);
        if (!sendPacketMessageToClient(app,message,version)) {
          Log.w(TAG,"String_Node_Str" + app.appId);
          return false;
        }
        ByteArrayMessageSpliter splitter=new ByteArrayMessageSpliter(appid,TransportConstants.ROUTER_RECEIVED_PACKET,bytes,0);
        while (splitter.isActive()) {
          if (!sendPacketMessageToClient(app,splitter.nextMessage(),version)) {
            Log.w(TAG,"String_Node_Str" + app.appId);
            splitter.close();
            return false;
          }
        }
      }
    }
 else {
      Log.e(TAG,"String_Node_Str");
      if (removeSessionFromMap(session)) {
        Log.i(TAG,"String_Node_Str");
        attemptToCleanUpModule(session,packet.getVersion());
      }
 else {
        if (packet.getFrameType() == FrameType.Single && packet.getServiceType() == SdlPacket.SERVICE_TYPE_RPC) {
          BinaryFrameHeader binFrameHeader=BinaryFrameHeader.parseBinaryHeader(packet.getPayload());
          if (binFrameHeader != null && FunctionID.UNREGISTER_APP_INTERFACE.getId() == binFrameHeader.getFunctionID()) {
            Log.d(TAG,"String_Node_Str");
          }
 else {
            attemptToCleanUpModule(session,packet.getVersion());
          }
        }
 else         if ((packet.getFrameType() == FrameType.Control && (packet.getFrameInfo() == SdlPacket.FRAME_INFO_END_SERVICE_ACK || packet.getFrameInfo() == SdlPacket.FRAME_INFO_END_SERVICE_NAK))) {
          Log.d(TAG,"String_Node_Str");
        }
 else {
          attemptToCleanUpModule(session,packet.getVersion());
        }
      }
    }
  }
  return false;
}