comparison src/http/v2/ngx_http_v2.c @ 6957:83bae3d354ab

HTTP/2: fixed connection finalization. All streams in connection must be finalized before the connection itself can be finalized and all related memory is freed. That's not always possible on the current event loop iteration. Thus when the last stream is finalized, it sets the special read event handler ngx_http_v2_handle_connection_handler() and posts the event. Previously, this handler didn't check the connection state and could call the regular event handler on a connection that was already in finalization stage. In the worst case that could lead to a segmentation fault, since some data structures aren't supposed to be used during connection finalization. Particularly, the waiting queue can contain already freed streams, so the WINDOW_UPDATE frame received by that moment could trigger accessing to these freed streams. Now, the connection error flag is explicitly checked in ngx_http_v2_handle_connection_handler().
author Valentin Bartenev <vbart@nginx.com>
date Wed, 29 Mar 2017 20:21:01 +0300
parents 9b5f31fdb850
children 28dc369899ea
comparison
equal deleted inserted replaced
6956:9b5f31fdb850 6957:83bae3d354ab
4132 ngx_http_v2_connection_t *h2c; 4132 ngx_http_v2_connection_t *h2c;
4133 4133
4134 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, 4134 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0,
4135 "http2 handle connection handler"); 4135 "http2 handle connection handler");
4136 4136
4137 c = rev->data;
4138 h2c = c->data;
4139
4140 if (c->error) {
4141 ngx_http_v2_finalize_connection(h2c, 0);
4142 return;
4143 }
4144
4137 rev->handler = ngx_http_v2_read_handler; 4145 rev->handler = ngx_http_v2_read_handler;
4138 4146
4139 if (rev->ready) { 4147 if (rev->ready) {
4140 ngx_http_v2_read_handler(rev); 4148 ngx_http_v2_read_handler(rev);
4141 return; 4149 return;
4142 } 4150 }
4143
4144 c = rev->data;
4145 h2c = c->data;
4146 4151
4147 if (h2c->last_out && ngx_http_v2_send_output_queue(h2c) == NGX_ERROR) { 4152 if (h2c->last_out && ngx_http_v2_send_output_queue(h2c) == NGX_ERROR) {
4148 ngx_http_v2_finalize_connection(h2c, 0); 4153 ngx_http_v2_finalize_connection(h2c, 0);
4149 return; 4154 return;
4150 } 4155 }