Program: 8308
Project: 8308
Buggy source:
/** 
 * The IntentService calls this method from the default worker thread with the intent that started the service. When this method returns, IntentService stops the service, as appropriate.
 */
@Override protected void onHandleIntent(Intent intent){
  mActionCanceled.set(false);
  Bundle extras=intent.getExtras();
  if (extras == null) {
    Log.e(Constants.TAG,"String_Node_Str");
    return;
  }
  if (!(extras.containsKey(EXTRA_MESSENGER) || extras.containsKey(EXTRA_DATA) || (intent.getAction() == null))) {
    Log.e(Constants.TAG,"String_Node_Str");
    return;
  }
  Uri dataUri=intent.getData();
  mMessenger=(Messenger)extras.get(EXTRA_MESSENGER);
  Bundle data=extras.getBundle(EXTRA_DATA);
  if (data == null) {
    Log.e(Constants.TAG,"String_Node_Str");
    return;
  }
  Log.logDebugBundle(data,"String_Node_Str");
  ProviderHelper providerHelper=new ProviderHelper(this);
  String action=intent.getAction();
switch (action) {
case ACTION_CERTIFY_KEYRING:
{
      CertifyActionsParcel parcel=data.getParcelable(CERTIFY_PARCEL);
      CryptoInputParcel cryptoInput=data.getParcelable(EXTRA_CRYPTO_INPUT);
      String keyServerUri=data.getString(UPLOAD_KEY_SERVER);
      CertifyOperation op=new CertifyOperation(this,providerHelper,this,mActionCanceled);
      CertifyResult result=op.certify(parcel,cryptoInput,keyServerUri);
      sendMessageToHandler(MessageStatus.OKAY,result);
      break;
    }
case ACTION_CONSOLIDATE:
{
    ConsolidateResult result;
    if (data.containsKey(CONSOLIDATE_RECOVERY) && data.getBoolean(CONSOLIDATE_RECOVERY)) {
      result=new ProviderHelper(this).consolidateDatabaseStep2(this);
    }
 else {
      result=new ProviderHelper(this).consolidateDatabaseStep1(this);
    }
    sendMessageToHandler(MessageStatus.OKAY,result);
    break;
  }
case ACTION_DECRYPT_METADATA:
{
  CryptoInputParcel cryptoInput=data.getParcelable(EXTRA_CRYPTO_INPUT);
  PgpDecryptVerifyInputParcel input=data.getParcelable(DECRYPT_VERIFY_PARCEL);
  PgpDecryptVerify op=new PgpDecryptVerify(this,new ProviderHelper(this),this);
  DecryptVerifyResult decryptVerifyResult=op.execute(input,cryptoInput);
  sendMessageToHandler(MessageStatus.OKAY,decryptVerifyResult);
  break;
}
case ACTION_VERIFY_KEYBASE_PROOF:
{
try {
  Proof proof=new Proof(new JSONObject(data.getString(KEYBASE_PROOF)));
  setProgress(R.string.keybase_message_fetching_data,0,100);
  Prover prover=Prover.findProverFor(proof);
  if (prover == null) {
    sendProofError(getString(R.string.keybase_no_prover_found) + "String_Node_Str" + proof.getPrettyName());
    return;
  }
  if (!prover.fetchProofData()) {
    sendProofError(prover.getLog(),getString(R.string.keybase_problem_fetching_evidence));
    return;
  }
  String requiredFingerprint=data.getString(KEYBASE_REQUIRED_FINGERPRINT);
  if (!prover.checkFingerprint(requiredFingerprint)) {
    sendProofError(getString(R.string.keybase_key_mismatch));
    return;
  }
  String domain=prover.dnsTxtCheckRequired();
  if (domain != null) {
    DNSMessage dnsQuery=new Client().query(new Question(domain,Record.TYPE.TXT));
    if (dnsQuery == null) {
      sendProofError(prover.getLog(),getString(R.string.keybase_dns_query_failure));
      return;
    }
    Record[] records=dnsQuery.getAnswers();
    List<List<byte[]>> extents=new ArrayList<List<byte[]>>();
    for (    Record r : records) {
      Data d=r.getPayload();
      if (d instanceof TXT) {
        extents.add(((TXT)d).getExtents());
      }
    }
    if (!prover.checkDnsTxt(extents)) {
      sendProofError(prover.getLog(),null);
      return;
    }
  }
  byte[] messageBytes=prover.getPgpMessage().getBytes();
  if (prover.rawMessageCheckRequired()) {
    InputStream messageByteStream=PGPUtil.getDecoderStream(new ByteArrayInputStream(messageBytes));
    if (!prover.checkRawMessageBytes(messageByteStream)) {
      sendProofError(prover.getLog(),null);
      return;
    }
  }
  PgpDecryptVerify op=new PgpDecryptVerify(this,new ProviderHelper(this),this);
  PgpDecryptVerifyInputParcel input=new PgpDecryptVerifyInputParcel(messageBytes).setSignedLiteralData(true).setRequiredSignerFingerprint(requiredFingerprint);
  DecryptVerifyResult decryptVerifyResult=op.execute(input,new CryptoInputParcel());
  if (!decryptVerifyResult.success()) {
    OperationLog log=decryptVerifyResult.getLog();
    OperationResult.LogEntryParcel lastEntry=null;
    for (    OperationResult.LogEntryParcel entry : log) {
      lastEntry=entry;
    }
    sendProofError(getString(lastEntry.mType.getMsgId()));
    return;
  }
  if (!prover.validate(new String(decryptVerifyResult.getOutputBytes()))) {
    sendProofError(getString(R.string.keybase_message_payload_mismatch));
    return;
  }
  Bundle resultData=new Bundle();
  resultData.putString(ServiceProgressHandler.DATA_MESSAGE,"String_Node_Str");
  resultData.putString(ServiceProgressHandler.KEYBASE_PROOF_URL,prover.getProofUrl());
  resultData.putString(ServiceProgressHandler.KEYBASE_PRESENCE_URL,prover.getPresenceUrl());
  resultData.putString(ServiceProgressHandler.KEYBASE_PRESENCE_LABEL,prover.getPresenceLabel());
  sendMessageToHandler(MessageStatus.OKAY,resultData);
}
 catch (Exception e) {
  sendErrorToHandler(e);
}
break;
}
case ACTION_DECRYPT_VERIFY:
{
CryptoInputParcel cryptoInput=data.getParcelable(EXTRA_CRYPTO_INPUT);
PgpDecryptVerifyInputParcel input=data.getParcelable(DECRYPT_VERIFY_PARCEL);
PgpDecryptVerify op=new PgpDecryptVerify(this,new ProviderHelper(this),this);
DecryptVerifyResult decryptVerifyResult=op.execute(input,cryptoInput);
sendMessageToHandler(MessageStatus.OKAY,decryptVerifyResult);
break;
}
case ACTION_DELETE:
{
long[] masterKeyIds=data.getLongArray(DELETE_KEY_LIST);
boolean isSecret=data.getBoolean(DELETE_IS_SECRET);
DeleteOperation op=new DeleteOperation(this,new ProviderHelper(this),this);
DeleteResult result=op.execute(masterKeyIds,isSecret);
sendMessageToHandler(MessageStatus.OKAY,result);
break;
}
case ACTION_EDIT_KEYRING:
{
SaveKeyringParcel saveParcel=data.getParcelable(EDIT_KEYRING_PARCEL);
CryptoInputParcel cryptoInput=data.getParcelable(EXTRA_CRYPTO_INPUT);
EditKeyOperation op=new EditKeyOperation(this,providerHelper,this,mActionCanceled);
OperationResult result=op.execute(saveParcel,cryptoInput);
sendMessageToHandler(MessageStatus.OKAY,result);
break;
}
case ACTION_PROMOTE_KEYRING:
{
long keyRingId=data.getLong(PROMOTE_MASTER_KEY_ID);
byte[] cardAid=data.getByteArray(PROMOTE_CARD_AID);
long[] subKeyIds=data.getLongArray(PROMOTE_SUBKEY_IDS);
PromoteKeyOperation op=new PromoteKeyOperation(this,providerHelper,this,mActionCanceled);
PromoteKeyResult result=op.execute(keyRingId,cardAid,subKeyIds);
sendMessageToHandler(MessageStatus.OKAY,result);
break;
}
case ACTION_EXPORT_KEYRING:
{
boolean exportSecret=data.getBoolean(EXPORT_SECRET,false);
String outputFile=data.getString(EXPORT_FILENAME);
Uri outputUri=data.getParcelable(EXPORT_URI);
boolean exportAll=data.getBoolean(EXPORT_ALL);
long[] masterKeyIds=exportAll ? null : data.getLongArray(EXPORT_KEY_RING_MASTER_KEY_ID);
ImportExportOperation importExportOperation=new ImportExportOperation(this,new ProviderHelper(this),this);
ExportResult result;
if (outputFile != null) {
result=importExportOperation.exportToFile(masterKeyIds,exportSecret,outputFile);
}
 else {
result=importExportOperation.exportToUri(masterKeyIds,exportSecret,outputUri);
}
sendMessageToHandler(MessageStatus.OKAY,result);
break;
}
case ACTION_IMPORT_KEYRING:
{
String keyServer=data.getString(IMPORT_KEY_SERVER);
ArrayList<ParcelableKeyRing> list=data.getParcelableArrayList(IMPORT_KEY_LIST);
ParcelableFileCache<ParcelableKeyRing> cache=new ParcelableFileCache<>(this,"String_Node_Str");
ImportExportOperation importExportOperation=new ImportExportOperation(this,providerHelper,this,mActionCanceled);
ImportKeyResult result=list != null ? importExportOperation.importKeyRings(list,keyServer) : importExportOperation.importKeyRings(cache,keyServer);
sendMessageToHandler(MessageStatus.OKAY,result);
break;
}
case ACTION_SIGN_ENCRYPT:
{
SignEncryptParcel inputParcel=data.getParcelable(SIGN_ENCRYPT_PARCEL);
CryptoInputParcel cryptoInput=data.getParcelable(EXTRA_CRYPTO_INPUT);
SignEncryptOperation op=new SignEncryptOperation(this,new ProviderHelper(this),this,mActionCanceled);
SignEncryptResult result=op.execute(inputParcel,cryptoInput);
sendMessageToHandler(MessageStatus.OKAY,result);
break;
}
case ACTION_UPLOAD_KEYRING:
{
try {
String keyServer=data.getString(UPLOAD_KEY_SERVER);
HkpKeyserver server=new HkpKeyserver(keyServer);
CanonicalizedPublicKeyRing keyring=providerHelper.getCanonicalizedPublicKeyRing(dataUri);
ImportExportOperation importExportOperation=new ImportExportOperation(this,new ProviderHelper(this),this);
try {
importExportOperation.uploadKeyRingToServer(server,keyring);
}
 catch (Keyserver.AddKeyException e) {
throw new PgpGeneralException("String_Node_Str");
}
sendMessageToHandler(MessageStatus.OKAY);
}
 catch (Exception e) {
sendErrorToHandler(e);
}
break;
}
}
}

Fixed version (ground truth):
/** 
 * The IntentService calls this method from the default worker thread with the intent that started the service. When this method returns, IntentService stops the service, as appropriate.
 */
@Override protected void onHandleIntent(Intent intent){
  mActionCanceled.set(false);
  Bundle extras=intent.getExtras();
  if (extras == null) {
    Log.e(Constants.TAG,"String_Node_Str");
    return;
  }
  if (!(extras.containsKey(EXTRA_MESSENGER) || extras.containsKey(EXTRA_DATA) || (intent.getAction() == null))) {
    Log.e(Constants.TAG,"String_Node_Str");
    return;
  }
  Uri dataUri=intent.getData();
  mMessenger=(Messenger)extras.get(EXTRA_MESSENGER);
  Bundle data=extras.getBundle(EXTRA_DATA);
  if (data == null) {
    Log.e(Constants.TAG,"String_Node_Str");
    return;
  }
  Log.logDebugBundle(data,"String_Node_Str");
  ProviderHelper providerHelper=new ProviderHelper(this);
  String action=intent.getAction();
switch (action) {
case ACTION_CERTIFY_KEYRING:
{
      CertifyActionsParcel parcel=data.getParcelable(CERTIFY_PARCEL);
      CryptoInputParcel cryptoInput=data.getParcelable(EXTRA_CRYPTO_INPUT);
      String keyServerUri=data.getString(UPLOAD_KEY_SERVER);
      CertifyOperation op=new CertifyOperation(this,providerHelper,this,mActionCanceled);
      CertifyResult result=op.certify(parcel,cryptoInput,keyServerUri);
      sendMessageToHandler(MessageStatus.OKAY,result);
      break;
    }
case ACTION_CONSOLIDATE:
{
    ConsolidateResult result;
    if (data.containsKey(CONSOLIDATE_RECOVERY) && data.getBoolean(CONSOLIDATE_RECOVERY)) {
      result=new ProviderHelper(this).consolidateDatabaseStep2(this);
    }
 else {
      result=new ProviderHelper(this).consolidateDatabaseStep1(this);
    }
    sendMessageToHandler(MessageStatus.OKAY,result);
    break;
  }
case ACTION_DECRYPT_METADATA:
{
  CryptoInputParcel cryptoInput=data.getParcelable(EXTRA_CRYPTO_INPUT);
  PgpDecryptVerifyInputParcel input=data.getParcelable(DECRYPT_VERIFY_PARCEL);
  input.setDecryptMetadataOnly(true);
  PgpDecryptVerify op=new PgpDecryptVerify(this,new ProviderHelper(this),this);
  DecryptVerifyResult decryptVerifyResult=op.execute(input,cryptoInput);
  sendMessageToHandler(MessageStatus.OKAY,decryptVerifyResult);
  break;
}
case ACTION_VERIFY_KEYBASE_PROOF:
{
try {
  Proof proof=new Proof(new JSONObject(data.getString(KEYBASE_PROOF)));
  setProgress(R.string.keybase_message_fetching_data,0,100);
  Prover prover=Prover.findProverFor(proof);
  if (prover == null) {
    sendProofError(getString(R.string.keybase_no_prover_found) + "String_Node_Str" + proof.getPrettyName());
    return;
  }
  if (!prover.fetchProofData()) {
    sendProofError(prover.getLog(),getString(R.string.keybase_problem_fetching_evidence));
    return;
  }
  String requiredFingerprint=data.getString(KEYBASE_REQUIRED_FINGERPRINT);
  if (!prover.checkFingerprint(requiredFingerprint)) {
    sendProofError(getString(R.string.keybase_key_mismatch));
    return;
  }
  String domain=prover.dnsTxtCheckRequired();
  if (domain != null) {
    DNSMessage dnsQuery=new Client().query(new Question(domain,Record.TYPE.TXT));
    if (dnsQuery == null) {
      sendProofError(prover.getLog(),getString(R.string.keybase_dns_query_failure));
      return;
    }
    Record[] records=dnsQuery.getAnswers();
    List<List<byte[]>> extents=new ArrayList<List<byte[]>>();
    for (    Record r : records) {
      Data d=r.getPayload();
      if (d instanceof TXT) {
        extents.add(((TXT)d).getExtents());
      }
    }
    if (!prover.checkDnsTxt(extents)) {
      sendProofError(prover.getLog(),null);
      return;
    }
  }
  byte[] messageBytes=prover.getPgpMessage().getBytes();
  if (prover.rawMessageCheckRequired()) {
    InputStream messageByteStream=PGPUtil.getDecoderStream(new ByteArrayInputStream(messageBytes));
    if (!prover.checkRawMessageBytes(messageByteStream)) {
      sendProofError(prover.getLog(),null);
      return;
    }
  }
  PgpDecryptVerify op=new PgpDecryptVerify(this,new ProviderHelper(this),this);
  PgpDecryptVerifyInputParcel input=new PgpDecryptVerifyInputParcel(messageBytes).setSignedLiteralData(true).setRequiredSignerFingerprint(requiredFingerprint);
  DecryptVerifyResult decryptVerifyResult=op.execute(input,new CryptoInputParcel());
  if (!decryptVerifyResult.success()) {
    OperationLog log=decryptVerifyResult.getLog();
    OperationResult.LogEntryParcel lastEntry=null;
    for (    OperationResult.LogEntryParcel entry : log) {
      lastEntry=entry;
    }
    sendProofError(getString(lastEntry.mType.getMsgId()));
    return;
  }
  if (!prover.validate(new String(decryptVerifyResult.getOutputBytes()))) {
    sendProofError(getString(R.string.keybase_message_payload_mismatch));
    return;
  }
  Bundle resultData=new Bundle();
  resultData.putString(ServiceProgressHandler.DATA_MESSAGE,"String_Node_Str");
  resultData.putString(ServiceProgressHandler.KEYBASE_PROOF_URL,prover.getProofUrl());
  resultData.putString(ServiceProgressHandler.KEYBASE_PRESENCE_URL,prover.getPresenceUrl());
  resultData.putString(ServiceProgressHandler.KEYBASE_PRESENCE_LABEL,prover.getPresenceLabel());
  sendMessageToHandler(MessageStatus.OKAY,resultData);
}
 catch (Exception e) {
  sendErrorToHandler(e);
}
break;
}
case ACTION_DECRYPT_VERIFY:
{
CryptoInputParcel cryptoInput=data.getParcelable(EXTRA_CRYPTO_INPUT);
PgpDecryptVerifyInputParcel input=data.getParcelable(DECRYPT_VERIFY_PARCEL);
input.setDecryptMetadataOnly(false);
PgpDecryptVerify op=new PgpDecryptVerify(this,new ProviderHelper(this),this);
DecryptVerifyResult decryptVerifyResult=op.execute(input,cryptoInput);
sendMessageToHandler(MessageStatus.OKAY,decryptVerifyResult);
break;
}
case ACTION_DELETE:
{
long[] masterKeyIds=data.getLongArray(DELETE_KEY_LIST);
boolean isSecret=data.getBoolean(DELETE_IS_SECRET);
DeleteOperation op=new DeleteOperation(this,new ProviderHelper(this),this);
DeleteResult result=op.execute(masterKeyIds,isSecret);
sendMessageToHandler(MessageStatus.OKAY,result);
break;
}
case ACTION_EDIT_KEYRING:
{
SaveKeyringParcel saveParcel=data.getParcelable(EDIT_KEYRING_PARCEL);
CryptoInputParcel cryptoInput=data.getParcelable(EXTRA_CRYPTO_INPUT);
EditKeyOperation op=new EditKeyOperation(this,providerHelper,this,mActionCanceled);
OperationResult result=op.execute(saveParcel,cryptoInput);
sendMessageToHandler(MessageStatus.OKAY,result);
break;
}
case ACTION_PROMOTE_KEYRING:
{
long keyRingId=data.getLong(PROMOTE_MASTER_KEY_ID);
byte[] cardAid=data.getByteArray(PROMOTE_CARD_AID);
long[] subKeyIds=data.getLongArray(PROMOTE_SUBKEY_IDS);
PromoteKeyOperation op=new PromoteKeyOperation(this,providerHelper,this,mActionCanceled);
PromoteKeyResult result=op.execute(keyRingId,cardAid,subKeyIds);
sendMessageToHandler(MessageStatus.OKAY,result);
break;
}
case ACTION_EXPORT_KEYRING:
{
boolean exportSecret=data.getBoolean(EXPORT_SECRET,false);
String outputFile=data.getString(EXPORT_FILENAME);
Uri outputUri=data.getParcelable(EXPORT_URI);
boolean exportAll=data.getBoolean(EXPORT_ALL);
long[] masterKeyIds=exportAll ? null : data.getLongArray(EXPORT_KEY_RING_MASTER_KEY_ID);
ImportExportOperation importExportOperation=new ImportExportOperation(this,new ProviderHelper(this),this);
ExportResult result;
if (outputFile != null) {
result=importExportOperation.exportToFile(masterKeyIds,exportSecret,outputFile);
}
 else {
result=importExportOperation.exportToUri(masterKeyIds,exportSecret,outputUri);
}
sendMessageToHandler(MessageStatus.OKAY,result);
break;
}
case ACTION_IMPORT_KEYRING:
{
String keyServer=data.getString(IMPORT_KEY_SERVER);
ArrayList<ParcelableKeyRing> list=data.getParcelableArrayList(IMPORT_KEY_LIST);
ParcelableFileCache<ParcelableKeyRing> cache=new ParcelableFileCache<>(this,"String_Node_Str");
ImportExportOperation importExportOperation=new ImportExportOperation(this,providerHelper,this,mActionCanceled);
ImportKeyResult result=list != null ? importExportOperation.importKeyRings(list,keyServer) : importExportOperation.importKeyRings(cache,keyServer);
sendMessageToHandler(MessageStatus.OKAY,result);
break;
}
case ACTION_SIGN_ENCRYPT:
{
SignEncryptParcel inputParcel=data.getParcelable(SIGN_ENCRYPT_PARCEL);
CryptoInputParcel cryptoInput=data.getParcelable(EXTRA_CRYPTO_INPUT);
SignEncryptOperation op=new SignEncryptOperation(this,new ProviderHelper(this),this,mActionCanceled);
SignEncryptResult result=op.execute(inputParcel,cryptoInput);
sendMessageToHandler(MessageStatus.OKAY,result);
break;
}
case ACTION_UPLOAD_KEYRING:
{
try {
String keyServer=data.getString(UPLOAD_KEY_SERVER);
HkpKeyserver server=new HkpKeyserver(keyServer);
CanonicalizedPublicKeyRing keyring=providerHelper.getCanonicalizedPublicKeyRing(dataUri);
ImportExportOperation importExportOperation=new ImportExportOperation(this,new ProviderHelper(this),this);
try {
importExportOperation.uploadKeyRingToServer(server,keyring);
}
 catch (Keyserver.AddKeyException e) {
throw new PgpGeneralException("String_Node_Str");
}
sendMessageToHandler(MessageStatus.OKAY);
}
 catch (Exception e) {
sendErrorToHandler(e);
}
break;
}
}
}