Openssl SSL_CTX_new is successfull but set errno to ENOSYS (Function not implemented)

1

The SSL_CTX_new() function works fine but something is strange it sets errno to ENOSYS.

Documentation doesn't say anything about this : https://www.openssl.org/docs/man1.1.1/man3/SSL_CTX_new.html

#include <errno.h>
#include <openssl/ssl.h>

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

    SSL_library_init();
    SSL_load_error_strings();

    perror("A");

    SSL_CTX * sslContext = SSL_CTX_new(TLS_server_method());

    if (sslContext == NULL){
        return EXIT_FAILURE;
    }

    perror("B");

    return 0;
}

this code returns this :

A: Undefined error: 0
B: Function not implemented

My openssl version is : OpenSSL 1.1.1b 26 Feb 2019

Maloux

Posted 2019-05-27T10:13:57.110

Reputation: 13

Welcome to Super User! What problem are you trying to solve? This seems quite programming-related. – bertieb – 2019-05-27T10:18:38.623

thanks :) I'm trying to understand why SSL_CTX_new sets errno. It might means there is an error somewhere – Maloux – 2019-05-27T10:21:43.180

If this is about a program you yourself are writing and compiling, and your question is about an API giving you an error, it might be better off one of our sister sites such as Stack Overflow

– bertieb – 2019-05-27T10:24:12.493

yes it is a program i wrote, i will move to stack overflow, thx – Maloux – 2019-05-27T10:25:48.480

Answers

1

Not all libraries use errno to report status. If the documentation does not explicitly say that this function sets errno, then the value is best thought of as undefined: the function might preserve the original value, or set it to 0, or leave some garbage in it.

And indeed the OpenSSL documentation does not say anything about errno; instead the library has its own "error stack" that you can access using ERR_get_error(), and this provides more precise error codes and messages than the very limited set provided by libc.

So the value you find in errno is just a leftover from some or other libc function that SSL_CTX_new() used internally. (For example, it might have tried to seed the RNG by calling libc getrandom(), which then returned ENOSYS due to lack of kernel support.)

user1686

Posted 2019-05-27T10:13:57.110

Reputation: 283 655