]> git.kaiwu.me - nginx.git/commitdiff
SSL: clear error queue after OPENSSL_init_ssl().
authorSergey Kandaurov <pluknet@nginx.com>
Mon, 6 Feb 2017 15:38:06 +0000 (18:38 +0300)
committerSergey Kandaurov <pluknet@nginx.com>
Mon, 6 Feb 2017 15:38:06 +0000 (18:38 +0300)
The function may leave error in the error queue while returning success,
e.g., when taking a DSO reference to itself as of OpenSSL 1.1.0d:
https://git.openssl.org/?p=openssl.git;a=commit;h=4af9f7f

Notably, this fixes alert seen with statically linked OpenSSL on some platforms.

While here, check OPENSSL_init_ssl() return value.

src/event/ngx_event_openssl.c

index 3c74b7b21b61016974346116d640a1bdfae05b8c..8c7c67704cdd35af5bc5b375d747e96d0830b092 100644 (file)
@@ -121,7 +121,17 @@ ngx_ssl_init(ngx_log_t *log)
 {
 #if OPENSSL_VERSION_NUMBER >= 0x10100003L
 
-    OPENSSL_init_ssl(OPENSSL_INIT_LOAD_CONFIG, NULL);
+    if (OPENSSL_init_ssl(OPENSSL_INIT_LOAD_CONFIG, NULL) == 0) {
+        ngx_ssl_error(NGX_LOG_ALERT, log, 0, "OPENSSL_init_ssl() failed");
+        return NGX_ERROR;
+    }
+
+    /*
+     * OPENSSL_init_ssl() may leave errors in the error queue
+     * while returning success
+     */
+
+    ERR_clear_error();
 
 #else