Program: 80247
Project: 80247
Buggy source:
static byte[] postSign(final String digestAlgorithmName,final byte[] content,final X509Certificate[] signerCertificateChain,final String policyIdentifier,final String policyQualifier,final boolean signingCertificateV2,final byte[] messageDigest,final byte[] signature) throws AOException {
  if (signerCertificateChain == null || signerCertificateChain.length == 0) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  final TBSCertificateStructure tbsCertificateStructure;
  try {
    tbsCertificateStructure=TBSCertificateStructure.getInstance(ASN1Object.fromByteArray(signerCertificateChain[0].getTBSCertificate()));
  }
 catch (  final Exception e) {
    throw new AOException("String_Node_Str",e);
  }
  final SignerIdentifier signerIdentifier=new SignerIdentifier(new IssuerAndSerialNumber(X500Name.getInstance(tbsCertificateStructure.getIssuer()),tbsCertificateStructure.getSerialNumber().getValue()));
  final AlgorithmIdentifier digestAlgorithmOID;
  try {
    digestAlgorithmOID=SigUtils.makeAlgId(AOAlgorithmID.getOID(digestAlgorithmName));
  }
 catch (  final Exception e) {
    throw new AOException("String_Node_Str",e);
  }
  final AlgorithmIdentifier keyAlgorithmIdentifier;
  try {
    keyAlgorithmIdentifier=SigUtils.makeAlgId(AOAlgorithmID.getOID("String_Node_Str"));
  }
 catch (  final Exception e) {
    throw new AOException("String_Node_Str",e);
  }
  final ASN1OctetString encodedPKCS1Signature=new DEROctetString(signature);
  final ASN1Set signedAttributes;
  try {
    signedAttributes=SigUtils.getAttributeSet(new AttributeTable(CAdESUtils.generateSignerInfo(signerCertificateChain[0],digestAlgorithmName,content,policyIdentifier,policyQualifier,signingCertificateV2,messageDigest)));
  }
 catch (  Exception e) {
    throw new AOException("String_Node_Str",e);
  }
  final ASN1EncodableVector signerInfo=new ASN1EncodableVector();
  signerInfo.add(new SignerInfo(signerIdentifier,digestAlgorithmOID,signedAttributes,keyAlgorithmIdentifier,encodedPKCS1Signature,null));
  final ContentInfo contentInfo;
  if (content != null) {
    final ByteArrayOutputStream baos=new ByteArrayOutputStream();
    final CMSProcessable msg=new CMSProcessableByteArray(content);
    try {
      msg.write(baos);
    }
 catch (    final Exception e) {
      throw new AOException("String_Node_Str",e);
    }
    contentInfo=new ContentInfo(new ASN1ObjectIdentifier(PKCSObjectIdentifiers.data.getId()),new BERConstructedOctetString(baos.toByteArray()));
  }
 else {
    contentInfo=new ContentInfo(new ASN1ObjectIdentifier(PKCSObjectIdentifiers.data.getId()),null);
  }
  final List<DEREncodable> ce=new ArrayList<DEREncodable>();
  for (  final X509Certificate cert : signerCertificateChain) {
    try {
      ce.add(X509CertificateStructure.getInstance(ASN1Object.fromByteArray(cert.getEncoded())));
    }
 catch (    final Exception e) {
      Logger.getLogger("String_Node_Str").severe("String_Node_Str" + AOUtil.getCN(cert) + "String_Node_Str");
    }
  }
  final ASN1Set certificates=SigUtils.createBerSetFromList(ce);
  final ASN1EncodableVector digestAlgorithms=new ASN1EncodableVector();
  digestAlgorithms.add(digestAlgorithmOID);
  return new ContentInfo(PKCSObjectIdentifiers.signedData,new SignedData(new DERSet(digestAlgorithms),contentInfo,certificates,null,new DERSet(signerInfo))).getDEREncoded();
}

Fixed version (ground truth):
static byte[] postSign(final String digestAlgorithmName,final byte[] content,final X509Certificate[] signerCertificateChain,final byte[] signature,final byte[] signedAttributes) throws AOException {
  if (signerCertificateChain == null || signerCertificateChain.length == 0) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  final TBSCertificateStructure tbsCertificateStructure;
  try {
    tbsCertificateStructure=TBSCertificateStructure.getInstance(ASN1Object.fromByteArray(signerCertificateChain[0].getTBSCertificate()));
  }
 catch (  final Exception e) {
    throw new AOException("String_Node_Str",e);
  }
  final SignerIdentifier signerIdentifier=new SignerIdentifier(new IssuerAndSerialNumber(X500Name.getInstance(tbsCertificateStructure.getIssuer()),tbsCertificateStructure.getSerialNumber().getValue()));
  final AlgorithmIdentifier digestAlgorithmOID;
  try {
    digestAlgorithmOID=SigUtils.makeAlgId(AOAlgorithmID.getOID(digestAlgorithmName));
  }
 catch (  final Exception e) {
    throw new AOException("String_Node_Str",e);
  }
  final AlgorithmIdentifier keyAlgorithmIdentifier;
  try {
    keyAlgorithmIdentifier=SigUtils.makeAlgId(AOAlgorithmID.getOID("String_Node_Str"));
  }
 catch (  final Exception e) {
    throw new AOException("String_Node_Str",e);
  }
  final ASN1OctetString encodedPKCS1Signature=new DEROctetString(signature);
  final ASN1Set asn1SignedAttributes;
  try {
    asn1SignedAttributes=(ASN1Set)ASN1Object.fromByteArray(signedAttributes);
  }
 catch (  IOException e) {
    throw new AOException("String_Node_Str",e);
  }
  final ASN1EncodableVector signerInfo=new ASN1EncodableVector();
  signerInfo.add(new SignerInfo(signerIdentifier,digestAlgorithmOID,asn1SignedAttributes,keyAlgorithmIdentifier,encodedPKCS1Signature,null));
  final ContentInfo contentInfo;
  if (content != null) {
    final ByteArrayOutputStream baos=new ByteArrayOutputStream();
    final CMSProcessable msg=new CMSProcessableByteArray(content);
    try {
      msg.write(baos);
    }
 catch (    final Exception e) {
      throw new AOException("String_Node_Str",e);
    }
    contentInfo=new ContentInfo(new ASN1ObjectIdentifier(PKCSObjectIdentifiers.data.getId()),new BERConstructedOctetString(baos.toByteArray()));
  }
 else {
    contentInfo=new ContentInfo(new ASN1ObjectIdentifier(PKCSObjectIdentifiers.data.getId()),null);
  }
  final List<DEREncodable> ce=new ArrayList<DEREncodable>();
  for (  final X509Certificate cert : signerCertificateChain) {
    try {
      ce.add(X509CertificateStructure.getInstance(ASN1Object.fromByteArray(cert.getEncoded())));
    }
 catch (    final Exception e) {
      Logger.getLogger("String_Node_Str").severe("String_Node_Str" + AOUtil.getCN(cert) + "String_Node_Str");
    }
  }
  final ASN1Set certificates=SigUtils.createBerSetFromList(ce);
  final ASN1EncodableVector digestAlgorithms=new ASN1EncodableVector();
  digestAlgorithms.add(digestAlgorithmOID);
  return new ContentInfo(PKCSObjectIdentifiers.signedData,new SignedData(new DERSet(digestAlgorithms),contentInfo,certificates,null,new DERSet(signerInfo))).getDEREncoded();
}