Program: 198759
Project: 198759
Buggy source:
/** 
 * Establish a VPN network and return the file descriptor of the VPN interface. This methods returns   {@code null} if the application isrevoked or not prepared.
 * @param config The parameters to configure the network.
 * @return The file descriptor of the VPN interface.
 */
public synchronized ParcelFileDescriptor establish(VpnConfig config){
  UserManager mgr=UserManager.get(mContext);
  if (Binder.getCallingUid() != mOwnerUID) {
    return null;
  }
  Intent intent=new Intent(VpnConfig.SERVICE_INTERFACE);
  intent.setClassName(mPackage,config.user);
  long token=Binder.clearCallingIdentity();
  try {
    UserInfo user=mgr.getUserInfo(mUserId);
    if (user.isRestricted() || mgr.hasUserRestriction(UserManager.DISALLOW_CONFIG_VPN)) {
      throw new SecurityException("String_Node_Str");
    }
    ResolveInfo info=AppGlobals.getPackageManager().resolveService(intent,null,0,mUserId);
    if (info == null) {
      throw new SecurityException("String_Node_Str" + config.user);
    }
    if (!BIND_VPN_SERVICE.equals(info.serviceInfo.permission)) {
      throw new SecurityException(config.user + "String_Node_Str" + BIND_VPN_SERVICE);
    }
  }
 catch (  RemoteException e) {
    throw new SecurityException("String_Node_Str" + config.user);
  }
 finally {
    Binder.restoreCallingIdentity(token);
  }
  VpnConfig oldConfig=mConfig;
  String oldInterface=mInterface;
  Connection oldConnection=mConnection;
  NetworkAgent oldNetworkAgent=mNetworkAgent;
  mNetworkAgent=null;
  List<UidRange> oldUsers=mVpnUsers;
  ParcelFileDescriptor tun=ParcelFileDescriptor.adoptFd(jniCreate(config.mtu));
  try {
    updateState(DetailedState.CONNECTING,"String_Node_Str");
    String interfaze=jniGetName(tun.getFd());
    StringBuilder builder=new StringBuilder();
    for (    LinkAddress address : config.addresses) {
      builder.append("String_Node_Str" + address);
    }
    if (jniSetAddresses(interfaze,builder.toString()) < 1) {
      throw new IllegalArgumentException("String_Node_Str");
    }
    Connection connection=new Connection();
    if (!mContext.bindServiceAsUser(intent,connection,Context.BIND_AUTO_CREATE,new UserHandle(mUserId))) {
      throw new IllegalStateException("String_Node_Str" + config.user);
    }
    mConnection=connection;
    mInterface=interfaze;
    config.user=mPackage;
    config.interfaze=mInterface;
    config.startTime=SystemClock.elapsedRealtime();
    mConfig=config;
    mVpnUsers=new ArrayList<UidRange>();
    agentConnect();
    if (oldConnection != null) {
      mContext.unbindService(oldConnection);
    }
    agentDisconnect(oldNetworkAgent);
    if (oldInterface != null && !oldInterface.equals(interfaze)) {
      jniReset(oldInterface);
    }
    try {
      IoUtils.setBlocking(tun.getFileDescriptor(),config.blocking);
    }
 catch (    IOException e) {
      throw new IllegalStateException("String_Node_Str" + config.blocking,e);
    }
  }
 catch (  RuntimeException e) {
    IoUtils.closeQuietly(tun);
    agentDisconnect();
    mConfig=oldConfig;
    mConnection=oldConnection;
    mVpnUsers=oldUsers;
    mNetworkAgent=oldNetworkAgent;
    mInterface=oldInterface;
    throw e;
  }
  Log.i(TAG,"String_Node_Str" + config.user + "String_Node_Str"+ mInterface);
  updateState(DetailedState.AUTHENTICATING,"String_Node_Str");
  return tun;
}

Fixed version (ground truth):
/** 
 * Establish a VPN network and return the file descriptor of the VPN interface. This methods returns   {@code null} if the application isrevoked or not prepared.
 * @param config The parameters to configure the network.
 * @return The file descriptor of the VPN interface.
 */
public synchronized ParcelFileDescriptor establish(VpnConfig config){
  UserManager mgr=UserManager.get(mContext);
  if (Binder.getCallingUid() != mOwnerUID) {
    return null;
  }
  Intent intent=new Intent(VpnConfig.SERVICE_INTERFACE);
  intent.setClassName(mPackage,config.user);
  long token=Binder.clearCallingIdentity();
  try {
    UserInfo user=mgr.getUserInfo(mUserId);
    if (user.isRestricted() || mgr.hasUserRestriction(UserManager.DISALLOW_CONFIG_VPN)) {
      throw new SecurityException("String_Node_Str");
    }
    ResolveInfo info=AppGlobals.getPackageManager().resolveService(intent,null,0,mUserId);
    if (info == null) {
      throw new SecurityException("String_Node_Str" + config.user);
    }
    if (!BIND_VPN_SERVICE.equals(info.serviceInfo.permission)) {
      throw new SecurityException(config.user + "String_Node_Str" + BIND_VPN_SERVICE);
    }
  }
 catch (  RemoteException e) {
    throw new SecurityException("String_Node_Str" + config.user);
  }
 finally {
    Binder.restoreCallingIdentity(token);
  }
  VpnConfig oldConfig=mConfig;
  String oldInterface=mInterface;
  Connection oldConnection=mConnection;
  NetworkAgent oldNetworkAgent=mNetworkAgent;
  mNetworkAgent=null;
  List<UidRange> oldUsers=mVpnUsers;
  ParcelFileDescriptor tun=ParcelFileDescriptor.adoptFd(jniCreate(config.mtu));
  try {
    updateState(DetailedState.CONNECTING,"String_Node_Str");
    String interfaze=jniGetName(tun.getFd());
    StringBuilder builder=new StringBuilder();
    for (    LinkAddress address : config.addresses) {
      builder.append("String_Node_Str" + address);
    }
    if (jniSetAddresses(interfaze,builder.toString()) < 1) {
      throw new IllegalArgumentException("String_Node_Str");
    }
    Connection connection=new Connection();
    if (!mContext.bindServiceAsUser(intent,connection,Context.BIND_AUTO_CREATE,new UserHandle(mUserId))) {
      throw new IllegalStateException("String_Node_Str" + config.user);
    }
    mConnection=connection;
    mInterface=interfaze;
    config.user=mPackage;
    config.interfaze=mInterface;
    config.startTime=SystemClock.elapsedRealtime();
    mConfig=config;
    mVpnUsers=new ArrayList<UidRange>();
    agentConnect();
    if (oldConnection != null) {
      mContext.unbindService(oldConnection);
    }
    agentDisconnect(oldNetworkAgent);
    if (oldInterface != null && !oldInterface.equals(interfaze)) {
      jniReset(oldInterface);
    }
    try {
      IoUtils.setBlocking(tun.getFileDescriptor(),config.blocking);
    }
 catch (    IOException e) {
      throw new IllegalStateException("String_Node_Str" + config.blocking,e);
    }
  }
 catch (  RuntimeException e) {
    IoUtils.closeQuietly(tun);
    agentDisconnect();
    mConfig=oldConfig;
    mConnection=oldConnection;
    mVpnUsers=oldUsers;
    mNetworkAgent=oldNetworkAgent;
    mInterface=oldInterface;
    throw e;
  }
  Log.i(TAG,"String_Node_Str" + config.user + "String_Node_Str"+ mInterface);
  return tun;
}