[英]Passing pointer to function causes segmentation fault when trying to retrieve value
I am getting a segmentation fault with the following code. 我收到以下代码的细分错误。 I am pretty sure it is because a function is trying to use the address of a variable instead of it's value.
我很确定这是因为函数正在尝试使用变量的地址而不是其值。 I am a bit new to pointers.
我对指针有点陌生。
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");
....
}
Using GDB, after makecsr has executed, I can print the value of priv_key_p and req_p no problem. 使用GDB,在makecsr执行后,我可以打印priv_key_p和req_p的值了。
However, inside the create_cert function, I can only print the value by writing p *priv_key_p / *req_p 但是,在create_cert函数内部,我只能通过写p * priv_key_p / * req_p来打印值
Error 错误
Program received signal SIGSEGV, Segmentation fault.
0xb7ebb747 in X509_REQ_get_pubkey ()
from /lib/i386-linux-gnu/libcrypto.so.1.0.0
your code: 您的代码:
if (!(pkey = X509_REQ_get_pubkey (req_p))) <--- Segementation fault here!
int_error ("Error getting public key from request");
....
try this one: 试试这个:
if (!(pkey == X509_REQ_get_pubkey (req_p))) <--- Segementation fault here!
int_error ("Error getting public key from request");
....
The error was because I was passing in a wrong pointer type for req_p into create_cert. 该错误是因为我将req_p的错误指针类型传递给create_cert。
Solution was to change create_cert to this: 解决方案是将create_cert更改为此:
int create_cert(X509 *req_p, X509 **cert, EVP_PKEY **priv_key_p, char * passphrase)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.