nginx h2 patch for 1.14.0 and fix spdy post bug#97
Open
favortel wants to merge 1 commit intocloudflare:masterfrom
Open
nginx h2 patch for 1.14.0 and fix spdy post bug#97favortel wants to merge 1 commit intocloudflare:masterfrom
favortel wants to merge 1 commit intocloudflare:masterfrom
Conversation
Nginx spdy post request will cause nginx segment fault in 1.14.0 and nginx-1.13.12
src/http/ngx_http_spdy.c:ngx_http_spdy_read_request_body
+ case NGX_SPDY_DATA_INTERNAL_ERROR:
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
+ }
+
// Cause problem in nginx-1.13.12 and 1.14.0
// r->request_body has been inited BEFORE calling ngx_http_spdy_read_request_body
// ngx_http_spdy_init_request_body will not run, and r->request_body->buf will be 0
+ if (!r->request_body && ngx_http_spdy_init_request_body(r) != NGX_OK) {
+ stream->skip_data = NGX_SPDY_DATA_INTERNAL_ERROR;
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
+ }
...
//IF patch for src/http/ngx_http.h still AFTER NGX_HTTP_V2
#if (NGX_HTTP_V2)
src/http/ngx_http_request_body.c
@@ -84,6 +84,12 @@ ngx_http_read_client_request_body(ngx_http_request_t *r,
goto done;
}
#endif
+#if (NGX_HTTP_SPDY)
+ if (r->spdy_stream) {
+ rc = ngx_http_spdy_read_request_body(r, post_handler);
+ goto done;
+ }
+#endif
http://lxr.nginx.org/source/src/http/ngx_http_request_body.c
0054 rb = ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t));
0055 if (rb == NULL) {
0056 rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
0057 goto done;
0058 }
0059
0060 /*
0061 * set by ngx_pcalloc():
0062 *
0063 * rb->bufs = NULL;
0064 * rb->buf = NULL;
0065 * rb->free = NULL;
0066 * rb->busy = NULL;
0067 * rb->chunked = NULL;
0068 */
0069
0070 rb->rest = -1;
0071 rb->post_handler = post_handler;
0072
0073 r->request_body = rb;
0074
0075 if (r->headers_in.content_length_n < 0 && !r->headers_in.chunked) {
0076 r->request_body_no_buffering = 0;
0077 post_handler(r);
0078 return NGX_OK;
0079 }
0080
0081 #if (NGX_HTTP_V2)
0082 if (r->stream) {
0083 rc = ngx_http_v2_read_request_body(r);
0084 goto done;
0085 }
0086 #endif
So, should use
+ if (!r->request_body->buf && ngx_http_spdy_init_request_body(r) != NGX_OK) {
+ stream->skip_data = NGX_SPDY_DATA_INTERNAL_ERROR;
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
+ }
OR move the code BEFORE r->request_body has been inited
+#if (NGX_HTTP_SPDY)
+ if (r->spdy_stream) {
+ rc = ngx_http_spdy_read_request_body(r, post_handler);
+ goto done;
+ }
+#endif
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Nginx SPDY POST request will cause nginx segment fault in 1.14.0 and nginx-1.13.12
src/http/ngx_http_spdy.c:ngx_http_spdy_state_read_databuf->last = ngx_cpymem(buf->last, pos, size);src/http/ngx_http_spdy.c:ngx_http_spdy_read_request_bodyCause problem in nginx-1.13.12 and 1.14.0, r->request_body has been inited BEFORE calling ngx_http_spdy_read_request_body in src/http/ngx_http_request_body.c.
So ngx_http_spdy_init_request_body will not run, and r->request_body->buf will be 0
If the patch for src/http/ngx_http_request_body.c still AFTER these codes:
The r->request_body has been inited beforce ngx_http_spdy_read_request_body called,
ngx_http_spdy_init_request_body will not run, and r->request_body->buf will be 0
https://github.com/cloudflare/sslconfig/blob/master/patches/nginx__1.13.0_http2_spdy.patchhttp://lxr.nginx.org/source/src/http/ngx_http_request_body.c0070-0073Which is different with nginx 1.12.2
http://lxr.nginx.org/source/src/http/ngx_http_request_body.c?v=nginx-1.12.2So, I use "r->request_body->buf" replace "r->request_body"
Or you can move the following code BEFORE r->request_body has been inited