]> git.kaiwu.me - nginx.git/commitdiff
SSL: separate checks for errors in ngx_ssl_read_password_file().
authorMaxim Dounin <mdounin@mdounin.ru>
Thu, 31 Jan 2019 16:36:51 +0000 (19:36 +0300)
committerMaxim Dounin <mdounin@mdounin.ru>
Thu, 31 Jan 2019 16:36:51 +0000 (19:36 +0300)
Checking multiple errors at once is a bad practice, as in general
it is not guaranteed that an object can be used after the error.
In this particular case, checking errors after multiple allocations
can result in excessive errors being logged when there is no memory
available.

src/event/ngx_event_openssl.c

index 7002059c6a6506e36dd98062ee1cf4878d130109..aa5ccdd33f336a54dee100676ff979730743f8a6 100644 (file)
@@ -947,10 +947,13 @@ ngx_ssl_read_password_file(ngx_conf_t *cf, ngx_str_t *file)
         return NULL;
     }
 
-    cln = ngx_pool_cleanup_add(cf->temp_pool, 0);
     passwords = ngx_array_create(cf->temp_pool, 4, sizeof(ngx_str_t));
+    if (passwords == NULL) {
+        return NULL;
+    }
 
-    if (cln == NULL || passwords == NULL) {
+    cln = ngx_pool_cleanup_add(cf->temp_pool, 0);
+    if (cln == NULL) {
         return NULL;
     }