我正在使用openssl加密文件,并且出现如下所示的malloc错误。
openssl version
OpenSSL 1.0.2j-fips 26 Sep 2016
openssl command
openssl cms -sign -in infile -signer file.crt.pem -inkey file.key.pem -CAfile CAfile -out outfile -keyopt rsa_padding_mode:pss -certfile by_hash/81908841
Errors
1435735688:error:2E0A40AF:CMS routines:CMS_add0_cert:certificate already present:cms_lib.c:462:
1435735688:error:2E094041:CMS routines:CMS_sign:malloc failure:cms_smime.c:461:
请注意,我100%确定我提供的参数100%正确(即infile,outfile,certfile,keyfile,cafile和hash_file)
预先感谢
答案 0 :(得分:-1)
如何修复openssl的malloc失败错误?
如果我正确解析了内容,则好像CMS_add1_cert
失败了。可能不是内存错误(或者可能是由于解析错误导致参数尺寸过大)。
OpenSSL 1.0.2.j是Commit e216bf9d7ca7。这是cms.c
,cms_smime.c:461
的功能如下所示。
第461行是代码:
merr:
CMSerr(CMS_F_CMS_SIGN, ERR_R_MALLOC_FAILURE);
我猜这是从这里来的:
for (i = 0; i < sk_X509_num(certs); i++) {
X509 *x = sk_X509_value(certs, i);
if (!CMS_add1_cert(cms, x))
goto merr;
}
我们真的不能多说,因为没有足够的信息,例如证书和其他参数。下一步是安装符号,然后将代码放在调试器下。
这里是CMS_sign
,它提供了返回错误的函数。
CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey,
STACK_OF(X509) *certs, BIO *data,
unsigned int flags)
{
CMS_ContentInfo *cms;
int i;
cms = CMS_ContentInfo_new();
if (!cms || !CMS_SignedData_init(cms))
goto merr;
if (pkey && !CMS_add1_signer(cms, signcert, pkey, NULL, flags)) {
CMSerr(CMS_F_CMS_SIGN, CMS_R_ADD_SIGNER_ERROR);
goto err;
}
for (i = 0; i < sk_X509_num(certs); i++) {
X509 *x = sk_X509_value(certs, i);
if (!CMS_add1_cert(cms, x))
goto merr;
}
if (!(flags & CMS_DETACHED))
CMS_set_detached(cms, 0);
if ((flags & (CMS_STREAM | CMS_PARTIAL))
|| CMS_final(cms, data, NULL, flags))
return cms;
else
goto err;
merr:
CMSerr(CMS_F_CMS_SIGN, ERR_R_MALLOC_FAILURE);
err:
if (cms)
CMS_ContentInfo_free(cms);
return NULL;
}