Home > OS >  Openssl ERR_error_string error description returns null
Openssl ERR_error_string error description returns null

Time:01-21

Trying to print OpenSSL error descriptions:

for (unsigned long int  er_code=0;er_code<100;er_code  )
{
char * err_data;
ERR_error_string(er_code, err_data);
printf("error code: %lu data: %s\n", er_code, err_data); 
}

Got all null's. What I do wrong?

CodePudding user response:

err_data is an unitialized pointer. According to the documentation, "buf must be at least 256 bytes long."

So try:

for (unsigned long int er_code = 0; er_code < 100; er_code  )
{
    char err_data[256];
    ERR_error_string(er_code, err_data);
    printf("error code: %lu data: %s\n", er_code, err_data);
}

Or, "If buf is NULL, the error string is placed in a static buffer." So you could also do:

for (unsigned long int er_code = 0; er_code < 100; er_code  )
{
    char* err_data = ERR_error_string(er_code, NULL);
    printf("error code: %lu data: %s\n", er_code, err_data);
}
  •  Tags:  
  • Related