Program: 2878
Project: 2878
Buggy source:
/** 
 * Purge and re-add all rules.
 * @param ctx application context (mandatory)
 * @param showErrors indicates if errors should be alerted
 */
public static boolean applyIptablesRules(Context ctx,boolean showErrors){
  if (ctx == null) {
    return false;
  }
  final SharedPreferences prefs=ctx.getSharedPreferences(PREFS_NAME,0);
  final boolean whitelist=prefs.getString(PREF_MODE,MODE_WHITELIST).equals(MODE_WHITELIST);
  final String itfs=prefs.getString(PREF_ITFS,ITF_3G);
  String itfFilter;
  if (itfs.indexOf("String_Node_Str") != -1) {
    itfFilter="String_Node_Str";
  }
 else   if (itfs.indexOf(ITF_3G) != -1) {
    itfFilter="String_Node_Str";
    ;
  }
 else {
    itfFilter="String_Node_Str";
    ;
  }
  final DroidApp[] apps=getApps(ctx);
  final StringBuilder newuids=new StringBuilder();
  for (int i=0; i < apps.length; i++) {
    if (apps[i].selected) {
      if (newuids.length() != 0)       newuids.append('|');
      newuids.append(apps[i].username);
    }
  }
  if (!newuids.toString().equals(prefs.getString(PREF_ALLOWEDUIDS,"String_Node_Str"))) {
    Editor edit=prefs.edit();
    edit.putString(PREF_ALLOWEDUIDS,newuids.toString());
    edit.commit();
  }
  final StringBuilder script=new StringBuilder();
  try {
    int code;
    script.append("String_Node_Str");
    final String targetRule=(whitelist ? "String_Node_Str" : "String_Node_Str");
    for (    DroidApp app : apps) {
      if (app.selected) {
        script.append("String_Node_Str" + itfFilter + "String_Node_Str"+ app.uid+ "String_Node_Str"+ targetRule+ "String_Node_Str");
      }
    }
    if (whitelist) {
      script.append("String_Node_Str" + itfFilter + "String_Node_Str");
    }
    StringBuilder res=new StringBuilder();
    code=runScriptAsRoot(script.toString(),res);
    if (showErrors && code != 0) {
      String msg=res.toString();
      Log.e("String_Node_Str",msg);
      if (msg.indexOf("String_Node_Str") != -1 || msg.indexOf("String_Node_Str") != -1) {
        alert(ctx,"String_Node_Str" + code + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
      }
 else {
        if (msg.indexOf("String_Node_Str") != -1) {
          msg=msg.replace("String_Node_Str","String_Node_Str");
        }
        alert(ctx,"String_Node_Str" + code + "String_Node_Str"+ msg.trim());
      }
    }
 else {
      return true;
    }
  }
 catch (  Exception e) {
    if (showErrors)     alert(ctx,"String_Node_Str" + e);
  }
  return false;
}

Fixed version (ground truth):
/** 
 * Purge and re-add all rules.
 * @param ctx application context (mandatory)
 * @param showErrors indicates if errors should be alerted
 */
public static boolean applyIptablesRules(Context ctx,boolean showErrors){
  if (ctx == null) {
    return false;
  }
  final SharedPreferences prefs=ctx.getSharedPreferences(PREFS_NAME,0);
  final boolean whitelist=prefs.getString(PREF_MODE,MODE_WHITELIST).equals(MODE_WHITELIST);
  boolean wifi=false;
  final String itfs=prefs.getString(PREF_ITFS,ITF_3G);
  String itfFilter;
  if (itfs.indexOf("String_Node_Str") != -1) {
    itfFilter="String_Node_Str";
    wifi=true;
  }
 else   if (itfs.indexOf(ITF_3G) != -1) {
    itfFilter="String_Node_Str";
    ;
  }
 else {
    itfFilter="String_Node_Str";
    ;
    wifi=true;
  }
  final DroidApp[] apps=getApps(ctx);
  final StringBuilder newuids=new StringBuilder();
  for (int i=0; i < apps.length; i++) {
    if (apps[i].selected) {
      if (newuids.length() != 0)       newuids.append('|');
      newuids.append(apps[i].username);
    }
  }
  if (!newuids.toString().equals(prefs.getString(PREF_ALLOWEDUIDS,"String_Node_Str"))) {
    Editor edit=prefs.edit();
    edit.putString(PREF_ALLOWEDUIDS,newuids.toString());
    edit.commit();
  }
  final StringBuilder script=new StringBuilder();
  try {
    int code;
    script.append("String_Node_Str");
    final String targetRule=(whitelist ? "String_Node_Str" : "String_Node_Str");
    if (whitelist && wifi) {
      int uid=android.os.Process.getUidForName("String_Node_Str");
      if (uid != -1)       script.append("String_Node_Str" + itfFilter + "String_Node_Str"+ uid+ "String_Node_Str");
      uid=android.os.Process.getUidForName("String_Node_Str");
      if (uid != -1)       script.append("String_Node_Str" + itfFilter + "String_Node_Str"+ uid+ "String_Node_Str");
    }
    for (    DroidApp app : apps) {
      if (app.selected) {
        script.append("String_Node_Str" + itfFilter + "String_Node_Str"+ app.uid+ "String_Node_Str"+ targetRule+ "String_Node_Str");
      }
    }
    if (whitelist) {
      script.append("String_Node_Str" + itfFilter + "String_Node_Str");
    }
    StringBuilder res=new StringBuilder();
    code=runScriptAsRoot(script.toString(),res);
    if (showErrors && code != 0) {
      String msg=res.toString();
      Log.e("String_Node_Str",msg);
      if (msg.indexOf("String_Node_Str") != -1 || msg.indexOf("String_Node_Str") != -1) {
        alert(ctx,"String_Node_Str" + code + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
      }
 else {
        if (msg.indexOf("String_Node_Str") != -1) {
          msg=msg.replace("String_Node_Str","String_Node_Str");
        }
        alert(ctx,"String_Node_Str" + code + "String_Node_Str"+ msg.trim());
      }
    }
 else {
      return true;
    }
  }
 catch (  Exception e) {
    if (showErrors)     alert(ctx,"String_Node_Str" + e);
  }
  return false;
}