Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sign-file,extract-cert: avoid using deprecated ERR_get_error_line()

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.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Tested-by: R Nageswara Sastry <rnsastry@linux.ibm.com>
Reviewed-by: Neal Gompa <neal@gompa.dev>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>

authored by

Jan Stancek and committed by
Jarkko Sakkinen
467d60ed 300e6d41

+13 -20
+2 -2
certs/extract-cert.c
··· 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)
+3 -3
scripts/sign-file.c
··· 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 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
+8 -15
scripts/ssl-common.h
··· 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 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 - } 21 - 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 23 } 31 24 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 } \