ERR_get_error_line() is deprecated since OpenSSL 3.0. Use ERR_peek_error_line() instead, and combine display_openssl_errors() and drain_openssl_errors() to a single function where parameter decides if it should consume errors silently.
Unified · Split
| @@ -99,11 +99,11 @@ int main(int argc, char **argv) · 98 unmodified lines | ||
| 99 | 99 | parms.cert = NULL; |
| 100 | 100 | |
| 101 | 101 | ENGINE_load_builtin_engines(); |
| 102 | − drain_openssl_errors(); | |
| 102 | + drain_openssl_errors(__LINE__, 1); | |
| 103 | 103 | e = ENGINE_by_id("pkcs11"); |
| 104 | 104 | ERR(!e, "Load PKCS#11 ENGINE"); |
| 105 | 105 | if (ENGINE_init(e)) |
| 106 | − drain_openssl_errors(); | |
| 106 | + drain_openssl_errors(__LINE__, 1); | |
| 107 | 107 | else |
| 108 | 108 | ERR(1, "ENGINE_init"); |
| 109 | 109 | if (key_pass) |
| @@ -114,11 +114,11 @@ static EVP_PKEY *read_private_key(const char *private_key_name) · 113 unmodified lines | ||
| 114 | 114 | ENGINE *e; |
| 115 | 115 | |
| 116 | 116 | ENGINE_load_builtin_engines(); |
| 117 | − drain_openssl_errors(); | |
| 117 | + drain_openssl_errors(__LINE__, 1); | |
| 118 | 118 | e = ENGINE_by_id("pkcs11"); |
| 119 | 119 | ERR(!e, "Load PKCS#11 ENGINE"); |
| 120 | 120 | if (ENGINE_init(e)) |
| 121 | − drain_openssl_errors(); | |
| 121 | + drain_openssl_errors(__LINE__, 1); | |
| 122 | 122 | else |
| 123 | 123 | ERR(1, "ENGINE_init"); |
| 124 | 124 | if (key_pass) |
| @@ -273,7 +273,7 @@ int main(int argc, char **argv) · 148 unmodified lines | ||
| 273 | 273 | |
| 274 | 274 | /* Digest the module data. */ |
| 275 | 275 | OpenSSL_add_all_digests(); |
| 276 | − display_openssl_errors(__LINE__); | |
| 276 | + drain_openssl_errors(__LINE__, 0); | |
| 277 | 277 | digest_algo = EVP_get_digestbyname(hash_algo); |
| 278 | 278 | ERR(!digest_algo, "EVP_get_digestbyname"); |
| 279 | 279 | |
| @@ -3,7 +3,7 @@ · 2 unmodified lines | ||
| 3 | 3 | * SSL helper functions shared by sign-file and extract-cert. |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | −static void display_openssl_errors(int l) | |
| 6 | +static void drain_openssl_errors(int l, int silent) | |
| 7 | 7 | { |
| 8 | 8 | const char *file; |
| 9 | 9 | char buf[120]; |
| @@ -11,28 +11,21 @@ static void display_openssl_errors(int l) · 1 unmodified line | ||
| 11 | 11 | |
| 12 | 12 | if (ERR_peek_error() == 0) |
| 13 | 13 | return; |
| 14 | − fprintf(stderr, "At main.c:%d:\n", l); | |
| 14 | + if (!silent) | |
| 15 | + fprintf(stderr, "At main.c:%d:\n", l); | |
| 15 | 16 | |
| 16 | − while ((e = ERR_get_error_line(&file, &line))) { | |
| 17 | + while ((e = ERR_peek_error_line(&file, &line))) { | |
| 17 | 18 | ERR_error_string(e, buf); |
| 18 | − fprintf(stderr, "- SSL %s: %s:%d\n", buf, file, line); | |
| 19 | + if (!silent) | |
| 20 | + fprintf(stderr, "- SSL %s: %s:%d\n", buf, file, line); | |
| 21 | + ERR_get_error(); | |
| 19 | 22 | } |
| 20 | 23 | } |
| 21 | 24 | |
| 22 | −static void drain_openssl_errors(void) | |
| 23 | −{ | |
| 24 | − const char *file; | |
| 25 | − int line; | |
| 26 | − | |
| 27 | − if (ERR_peek_error() == 0) | |
| 28 | − return; | |
| 29 | − while (ERR_get_error_line(&file, &line)) {} | |
| 30 | −} | |
| 31 | − | |
| 32 | 25 | #define ERR(cond, fmt, ...) \ |
| 33 | 26 | do { \ |
| 34 | 27 | bool __cond = (cond); \ |
| 35 | − display_openssl_errors(__LINE__); \ | |
| 28 | + drain_openssl_errors(__LINE__, 0); \ | |
| 36 | 29 | if (__cond) { \ |
| 37 | 30 | errx(1, fmt, ## __VA_ARGS__); \ |
| 38 | 31 | } \ |