History

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.

Jan Stancek committed 2 years ago

Commit 467d60e1 parent 300e6d43 files · +13 −20Browse files

Showing the changes to scripts (2 of 3 files). Show all

Unified · Split

2 files
  1. scripts/sign-file.c +3 −3
  2. scripts/ssl-common.h +8 −15
scripts/sign-file.c+3−3
@@ -114,11 +114,11 @@ static EVP_PKEY *read_private_key(const char *private_key_name) · 113 unmodified lines
114 ENGINE *e;114 ENGINE *e;
115 115
116 ENGINE_load_builtin_engines();116 ENGINE_load_builtin_engines();
117 drain_openssl_errors();117 drain_openssl_errors(__LINE__, 1);
118 e = ENGINE_by_id("pkcs11");118 e = ENGINE_by_id("pkcs11");
119 ERR(!e, "Load PKCS#11 ENGINE");119 ERR(!e, "Load PKCS#11 ENGINE");
120 if (ENGINE_init(e))120 if (ENGINE_init(e))
121 drain_openssl_errors();121 drain_openssl_errors(__LINE__, 1);
122 else122 else
123 ERR(1, "ENGINE_init");123 ERR(1, "ENGINE_init");
124 if (key_pass)124 if (key_pass)
@@ -273,7 +273,7 @@ int main(int argc, char **argv) · 148 unmodified lines
273 273
274 /* Digest the module data. */274 /* Digest the module data. */
275 OpenSSL_add_all_digests();275 OpenSSL_add_all_digests();
276 display_openssl_errors(__LINE__);276 drain_openssl_errors(__LINE__, 0);
277 digest_algo = EVP_get_digestbyname(hash_algo);277 digest_algo = EVP_get_digestbyname(hash_algo);
278 ERR(!digest_algo, "EVP_get_digestbyname");278 ERR(!digest_algo, "EVP_get_digestbyname");
279 279
scripts/ssl-common.h+8−15
@@ -3,7 +3,7 @@ · 2 unmodified lines
3 * SSL helper functions shared by sign-file and extract-cert.3 * SSL helper functions shared by sign-file and extract-cert.
4 */4 */
5 5
6static void display_openssl_errors(int l)6static void drain_openssl_errors(int l, int silent)
7{7{
8 const char *file;8 const char *file;
9 char buf[120];9 char buf[120];
@@ -11,28 +11,21 @@ static void display_openssl_errors(int l) · 1 unmodified line
11 11
12 if (ERR_peek_error() == 0)12 if (ERR_peek_error() == 0)
13 return;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 ERR_error_string(e, buf);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
22static 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#define ERR(cond, fmt, ...) \25#define ERR(cond, fmt, ...) \
33 do { \26 do { \
34 bool __cond = (cond); \27 bool __cond = (cond); \
35 display_openssl_errors(__LINE__); \28 drain_openssl_errors(__LINE__, 0); \
36 if (__cond) { \29 if (__cond) { \
37 errx(1, fmt, ## __VA_ARGS__); \30 errx(1, fmt, ## __VA_ARGS__); \
38 } \31 } \