vico
vico

Reputation: 18175

Openssl ERR_error_string error description returns null

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?

Upvotes: 0

Views: 449

Answers (1)

Fred Larson
Fred Larson

Reputation: 62053

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);
}

Upvotes: 2

Related Questions