gpt4 book ai didi

c - 尝试检索值时,将指针传递给函数会导致段错误

转载 作者:行者123 更新时间:2023-11-30 17:46:25 24 4
gpt4 key购买 nike

我在使用以下代码时遇到段错误。我很确定这是因为函数试图使用变量的地址而不是它的值。我对指针有点陌生。

int main(int argc, char *argv[])
{

EVP_PKEY priv_key_p;
X509_REQ req_p;
X509 cert;
PKCS7 pkcs7;

/*Need to store value in req_p and priv_key_p*/
makecsr(&req_p, &priv_key_p, passphrase);

/*Need to use value of req_p and priv_key_p*/
create_cert(&req_p, &cert, &priv_key_p, passphrase);
}


int create_cert(X509_REQ *req_p, X509 *cert, EVP_PKEY *priv_key_p, char *passphrase)
{
int i;
long serial = 1;
EVP_PKEY *pkey;
const EVP_MD *digest;
X509_NAME *name;
X509V3_CTX ctx;

/* verify signature on the request */
if (!(pkey = X509_REQ_get_pubkey (req_p))) <--- Segmentation fault here!
int_error ("Error getting public key from request");
....
}

使用GDB,makecsr执行后,我可以毫无问题地打印priv_key_p和req_p的值。

但是,在 create_cert 函数内部,我只能通过写入 p *priv_key_p/*req_p 来打印该值

错误

Program received signal SIGSEGV, Segmentation fault.
0xb7ebb747 in X509_REQ_get_pubkey ()
from /lib/i386-linux-gnu/libcrypto.so.1.0.0

最佳答案

你的代码:

if (!(pkey = X509_REQ_get_pubkey (req_p))) <--- Segementation fault here!
int_error ("Error getting public key from request");
....

试试这个:

if (!(pkey == X509_REQ_get_pubkey (req_p))) <--- Segementation fault here!
int_error ("Error getting public key from request");
....

关于c - 尝试检索值时,将指针传递给函数会导致段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19293735/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com