ERR(3)

πŸ“¦ version 4.4.0, in alpine 3.24, arch rolling

πŸ’– NAME πŸ’–

ERR β€” OpenSSL error codes

okay bestie, welcome to the ERR(3) page from the Library Functions Manual β€” this is literally the group chat for OpenSSL error codes πŸ’…

🌸 SYNOPSIS 🌸

library β€œlibcrypto” #include <openssl/err.h>

✨ DESCRIPTION ✨

so when a call to the OpenSSL library fails, it’s usually signaled by the return value 😭 and an error code gets stored in an error queue that’s associated with the current thread. The ERR library is the bestie that hands you functions to obtain those error codes and textual error messages. Wanna know how to access error codes? The ERR_get_error(3) manpage describes that.

Error codes are carrying the lore: they contain information about where the error occurred and what went wrong πŸ‘‘ ERR_GET_LIB(3) describes how to extract this information. And the method to obtain human-readable error messages? That’s described in ERR_error_string(3).

Need to clear the error queue? ERR_clear_error(3) can do that, no cap.

⚠️ note bestie: ERR_remove_state(3) should be used to avoid memory leaks when threads are terminated. Not me forgetting that one πŸ™ˆ

πŸ› οΈ ADDING NEW ERROR CODES TO OPENSSL πŸ› οΈ

if you want to record error codes in the OpenSSL error system from within your application, see ERR_put_error(3) ✨

The remainder of this section is of interest only if you want to add new error codes to OpenSSL or add error codes from external libraries. iykyk.

When you are using new function or reason codes, run make errors. The necessary #defines will then automatically be added to the sub-library’s header file. slay.

🧚 Adding new libraries 🧚

When adding a new sub-library to OpenSSL, assign it a library number ERR_LIB_XXX, define a macro XXXerr() (both in <openssl/err.h>), add its name to ERR_str_libraries[] (in /usr/src/lib/libcrypto/err/err.c), and add ERR_load_XXX_strings() to the ERR_load_crypto_strings() function (in /usr/src/lib/libcrypto/err/err_all.c). Finally, add xxx_err.c to the Makefile. periodt πŸ’…

🌈 USING ERROR CODES IN EXTERNAL LIBRARIES 🌈

It is also possible to use OpenSSL’s error code scheme in external libraries. yes bestie, go off 🫢

πŸ” INTERNALS πŸ”

The error queues are stored in a hash table with one ERR_STATE entry for each PID. ERR_get_state() returns the current thread’s ERR_STATE. An ERR_STATE can hold up to ERR_NUM_ERRORS error codes. When more error codes are added, the old ones are overwritten, on the assumption that the most recent errors are most important. highkey makes sense.

Error strings are also stored in a hash table. iconic.

πŸ‘‘ SEE ALSO πŸ‘‘


cute sign-off: this page comes from Debian, dated June 8, 2025, and it’s ERR(3) β€” mwah πŸ’‹

πŸ“¦ where this page comes from