| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 56a6513 commit 2c1e3ab
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -52,11 +52,7 @@ typedef enum { | |||
| 52 | 52 | * Unlike NGHTTP2_ERR_IGN_HTTP_HEADER, this does not invoke | |
| 53 | 53 | * nghttp2_on_invalid_header_callback. | |
| 54 | 54 | */ | |
| 55 | - NGHTTP2_ERR_REMOVE_HTTP_HEADER = -106, | ||
| 56 | - /* | ||
| 57 | - * Cancel pushed stream. | ||
| 58 | - */ | ||
| 59 | - NGHTTP2_ERR_PUSH_CANCEL = -107, | ||
| 55 | + NGHTTP2_ERR_REMOVE_HTTP_HEADER = -106 | ||
| 60 | 56 | } nghttp2_internal_error; | |
| 61 | 57 | ||
| 62 | 58 | #endif /* !defined(NGHTTP2_INT_H) */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3272,9 +3272,7 @@ static int session_call_on_invalid_header(nghttp2_session *session, | |||
| 3272 | 3272 | session, frame, nv->name->base, nv->name->len, nv->value->base, | |
| 3273 | 3273 | nv->value->len, nv->flags, session->user_data); | |
| 3274 | 3274 | } else { | |
| 3275 | - /* If both callbacks are not set, the invalid field nv is | ||
| 3276 | - ignored. */ | ||
| 3277 | - return 0; | ||
| 3275 | + return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; | ||
| 3278 | 3276 | } | |
| 3279 | 3277 | ||
| 3280 | 3278 | if (rv == NGHTTP2_ERR_PAUSE || rv == NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE) { | |
@@ -3359,10 +3357,6 @@ static uint32_t get_error_code_from_lib_error_code(int lib_error_code) { | |||
| 3359 | 3357 | case NGHTTP2_ERR_HTTP_HEADER: | |
| 3360 | 3358 | case NGHTTP2_ERR_HTTP_MESSAGING: | |
| 3361 | 3359 | return NGHTTP2_PROTOCOL_ERROR; | |
| 3362 | - case NGHTTP2_ERR_INTERNAL: | ||
| 3363 | - return NGHTTP2_INTERNAL_ERROR; | ||
| 3364 | - case NGHTTP2_ERR_PUSH_CANCEL: | ||
| 3365 | - return NGHTTP2_CANCEL; | ||
| 3366 | 3360 | default: | |
| 3367 | 3361 | return NGHTTP2_INTERNAL_ERROR; | |
| 3368 | 3362 | } | |
@@ -3414,7 +3408,7 @@ static int session_handle_invalid_stream2(nghttp2_session *session, | |||
| 3414 | 3408 | if (rv != 0) { | |
| 3415 | 3409 | return rv; | |
| 3416 | 3410 | } | |
| 3417 | - if (frame && session->callbacks.on_invalid_frame_recv_callback) { | ||
| 3411 | + if (session->callbacks.on_invalid_frame_recv_callback) { | ||
| 3418 | 3412 | if (session->callbacks.on_invalid_frame_recv_callback( | |
| 3419 | 3413 | session, frame, lib_error_code, session->user_data) != 0) { | |
| 3420 | 3414 | return NGHTTP2_ERR_CALLBACK_FAILURE; | |
@@ -3569,29 +3563,7 @@ static int inflate_header_block(nghttp2_session *session, nghttp2_frame *frame, | |||
| 3569 | 3563 | ||
| 3570 | 3564 | rv2 = session_call_on_invalid_header(session, frame, &nv); | |
| 3571 | 3565 | if (rv2 == NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE) { | |
| 3572 | - DEBUGF("recv: HTTP error: type=%u, id=%d, header %.*s: %.*s\n", | ||
| 3573 | - frame->hd.type, frame->hd.stream_id, (int)nv.name->len, | ||
| 3574 | - nv.name->base, (int)nv.value->len, nv.value->base); | ||
| 3575 | - | ||
| 3576 | - rv = session_call_error_callback( | ||
| 3577 | - session, NGHTTP2_ERR_HTTP_HEADER, | ||
| 3578 | - "Invalid HTTP header field was received: frame type: " | ||
| 3579 | - "%u, stream: %d, name: [%.*s], value: [%.*s]", | ||
| 3580 | - frame->hd.type, frame->hd.stream_id, (int)nv.name->len, | ||
| 3581 | - nv.name->base, (int)nv.value->len, nv.value->base); | ||
| 3582 | - | ||
| 3583 | - if (nghttp2_is_fatal(rv)) { | ||
| 3584 | - return rv; | ||
| 3585 | - } | ||
| 3586 | - | ||
| 3587 | - rv = session_handle_invalid_stream2( | ||
| 3588 | - session, subject_stream->stream_id, frame, | ||
| 3589 | - NGHTTP2_ERR_HTTP_HEADER); | ||
| 3590 | - if (nghttp2_is_fatal(rv)) { | ||
| 3591 | - return rv; | ||
| 3592 | - } | ||
| 3593 | - | ||
| 3594 | - return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; | ||
| 3566 | + rv = NGHTTP2_ERR_HTTP_HEADER; | ||
| 3595 | 3567 | } else { | |
| 3596 | 3568 | if (rv2 != 0) { | |
| 3597 | 3569 | return rv2; | |
@@ -3631,8 +3603,13 @@ static int inflate_header_block(nghttp2_session *session, nghttp2_frame *frame, | |||
| 3631 | 3603 | return rv; | |
| 3632 | 3604 | } | |
| 3633 | 3605 | ||
| 3634 | - return nghttp2_session_terminate_session(session, | ||
| 3635 | - NGHTTP2_PROTOCOL_ERROR); | ||
| 3606 | + rv = | ||
| 3607 | + session_handle_invalid_stream2(session, subject_stream->stream_id, | ||
| 3608 | + frame, NGHTTP2_ERR_HTTP_HEADER); | ||
| 3609 | + if (nghttp2_is_fatal(rv)) { | ||
| 3610 | + return rv; | ||
| 3611 | + } | ||
| 3612 | + return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; | ||
| 3636 | 3613 | } | |
| 3637 | 3614 | } | |
| 3638 | 3615 | if (rv == 0) { | |
@@ -3745,7 +3722,27 @@ static int session_after_header_block_received(nghttp2_session *session) { | |||
| 3745 | 3722 | } | |
| 3746 | 3723 | } | |
| 3747 | 3724 | if (rv != 0) { | |
| 3748 | - return nghttp2_session_terminate_session(session, NGHTTP2_PROTOCOL_ERROR); | ||
| 3725 | + int32_t stream_id; | ||
| 3726 | + | ||
| 3727 | + if (frame->hd.type == NGHTTP2_PUSH_PROMISE) { | ||
| 3728 | + stream_id = frame->push_promise.promised_stream_id; | ||
| 3729 | + } else { | ||
| 3730 | + stream_id = frame->hd.stream_id; | ||
| 3731 | + } | ||
| 3732 | + | ||
| 3733 | + rv = session_handle_invalid_stream2(session, stream_id, frame, | ||
| 3734 | + NGHTTP2_ERR_HTTP_MESSAGING); | ||
| 3735 | + if (nghttp2_is_fatal(rv)) { | ||
| 3736 | + return rv; | ||
| 3737 | + } | ||
| 3738 | + | ||
| 3739 | + if (frame->hd.type == NGHTTP2_HEADERS && | ||
| 3740 | + (frame->hd.flags & NGHTTP2_FLAG_END_STREAM)) { | ||
| 3741 | + nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD); | ||
| 3742 | + /* Don't call nghttp2_session_close_stream_if_shut_rdwr | ||
| 3743 | + because RST_STREAM has been submitted. */ | ||
| 3744 | + } | ||
| 3745 | + return 0; | ||
| 3749 | 3746 | } | |
| 3750 | 3747 | } | |
| 3751 | 3748 | ||
@@ -4081,7 +4078,8 @@ static int update_remote_initial_window_size_func(void *entry, void *ptr) { | |||
| 4081 | 4078 | rv = nghttp2_stream_update_remote_initial_window_size( | |
| 4082 | 4079 | stream, arg->new_window_size, arg->old_window_size); | |
| 4083 | 4080 | if (rv != 0) { | |
| 4084 | - return NGHTTP2_ERR_FLOW_CONTROL; | ||
| 4081 | + return nghttp2_session_add_rst_stream(arg->session, stream->stream_id, | ||
| 4082 | + NGHTTP2_FLOW_CONTROL_ERROR); | ||
| 4085 | 4083 | } | |
| 4086 | 4084 | ||
| 4087 | 4085 | /* If window size gets positive, push deferred DATA frame to | |
@@ -4107,8 +4105,6 @@ static int update_remote_initial_window_size_func(void *entry, void *ptr) { | |||
| 4107 | 4105 | * | |
| 4108 | 4106 | * NGHTTP2_ERR_NOMEM | |
| 4109 | 4107 | * Out of memory. | |
| 4110 | - * NGHTTP2_ERR_FLOW_CONTROL | ||
| 4111 | - * Window size gets out of range. | ||
| 4112 | 4108 | */ | |
| 4113 | 4109 | static int | |
| 4114 | 4110 | session_update_remote_initial_window_size(nghttp2_session *session, | |
@@ -4132,7 +4128,8 @@ static int update_local_initial_window_size_func(void *entry, void *ptr) { | |||
| 4132 | 4128 | rv = nghttp2_stream_update_local_initial_window_size( | |
| 4133 | 4129 | stream, arg->new_window_size, arg->old_window_size); | |
| 4134 | 4130 | if (rv != 0) { | |
| 4135 | - return NGHTTP2_ERR_FLOW_CONTROL; | ||
| 4131 | + return nghttp2_session_add_rst_stream(arg->session, stream->stream_id, | ||
| 4132 | + NGHTTP2_FLOW_CONTROL_ERROR); | ||
| 4136 | 4133 | } | |
| 4137 | 4134 | ||
| 4138 | 4135 | if (stream->window_update_queued) { | |
@@ -4166,8 +4163,6 @@ static int update_local_initial_window_size_func(void *entry, void *ptr) { | |||
| 4166 | 4163 | * | |
| 4167 | 4164 | * NGHTTP2_ERR_NOMEM | |
| 4168 | 4165 | * Out of memory. | |
| 4169 | - * NGHTTP2_ERR_FLOW_CONTROL | ||
| 4170 | - * Window size gets out of range. | ||
| 4171 | 4166 | */ | |
| 4172 | 4167 | static int | |
| 4173 | 4168 | session_update_local_initial_window_size(nghttp2_session *session, | |
@@ -4554,9 +4549,9 @@ int nghttp2_session_on_push_promise_received(nghttp2_session *session, | |||
| 4554 | 4549 | session->max_incoming_reserved_streams) { | |
| 4555 | 4550 | /* Currently, client does not retain closed stream, so we don't | |
| 4556 | 4551 | check NGHTTP2_SHUT_RD condition here. */ | |
| 4557 | - rv = session_handle_invalid_stream2(session, | ||
| 4558 | - frame->push_promise.promised_stream_id, | ||
| 4559 | - NULL, NGHTTP2_ERR_PUSH_CANCEL); | ||
| 4552 | + | ||
| 4553 | + rv = nghttp2_session_add_rst_stream( | ||
| 4554 | + session, frame->push_promise.promised_stream_id, NGHTTP2_CANCEL); | ||
| 4560 | 4555 | if (rv != 0) { | |
| 4561 | 4556 | return rv; | |
| 4562 | 4557 | } | |
@@ -4713,9 +4708,8 @@ static int session_on_stream_window_update_received(nghttp2_session *session, | |||
| 4713 | 4708 | } | |
| 4714 | 4709 | if (NGHTTP2_MAX_WINDOW_SIZE - frame->window_update.window_size_increment < | |
| 4715 | 4710 | stream->remote_window_size) { | |
| 4716 | - return session_handle_invalid_connection( | ||
| 4717 | - session, frame, NGHTTP2_ERR_FLOW_CONTROL, | ||
| 4718 | - "WINDOW_UPDATE: window size overflow"); | ||
| 4711 | + return session_handle_invalid_stream(session, frame, | ||
| 4712 | + NGHTTP2_ERR_FLOW_CONTROL); | ||
| 4719 | 4713 | } | |
| 4720 | 4714 | stream->remote_window_size += frame->window_update.window_size_increment; | |
| 4721 | 4715 | ||
@@ -4945,7 +4939,16 @@ int nghttp2_session_on_data_received(nghttp2_session *session, | |||
| 4945 | 4939 | if (session_enforce_http_messaging(session) && | |
| 4946 | 4940 | (frame->hd.flags & NGHTTP2_FLAG_END_STREAM)) { | |
| 4947 | 4941 | if (nghttp2_http_on_remote_end_stream(stream) != 0) { | |
| 4948 | - return nghttp2_session_terminate_session(session, NGHTTP2_PROTOCOL_ERROR); | ||
| 4942 | + rv = nghttp2_session_add_rst_stream(session, stream->stream_id, | ||
| 4943 | + NGHTTP2_PROTOCOL_ERROR); | ||
| 4944 | + if (nghttp2_is_fatal(rv)) { | ||
| 4945 | + return rv; | ||
| 4946 | + } | ||
| 4947 | + | ||
| 4948 | + nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD); | ||
| 4949 | + /* Don't call nghttp2_session_close_stream_if_shut_rdwr because | ||
| 4950 | + RST_STREAM has been submitted. */ | ||
| 4951 | + return 0; | ||
| 4949 | 4952 | } | |
| 4950 | 4953 | } | |
| 4951 | 4954 | ||
@@ -5003,8 +5006,8 @@ int nghttp2_session_update_recv_stream_window_size(nghttp2_session *session, | |||
| 5003 | 5006 | rv = adjust_recv_window_size(&stream->recv_window_size, delta_size, | |
| 5004 | 5007 | stream->local_window_size); | |
| 5005 | 5008 | if (rv != 0) { | |
| 5006 | - return nghttp2_session_terminate_session(session, | ||
| 5007 | - NGHTTP2_FLOW_CONTROL_ERROR); | ||
| 5009 | + return nghttp2_session_add_rst_stream(session, stream->stream_id, | ||
| 5010 | + NGHTTP2_FLOW_CONTROL_ERROR); | ||
| 5008 | 5011 | } | |
| 5009 | 5012 | /* We don't have to send WINDOW_UPDATE if the data received is the | |
| 5010 | 5013 | last chunk in the incoming stream. */ | |
@@ -5587,8 +5590,8 @@ nghttp2_ssize nghttp2_session_mem_recv2(nghttp2_session *session, | |||
| 5587 | 5590 | } | |
| 5588 | 5591 | ||
| 5589 | 5592 | if (rv == NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE) { | |
| 5590 | - rv = session_handle_invalid_stream2( | ||
| 5591 | - session, iframe->frame.hd.stream_id, NULL, NGHTTP2_ERR_INTERNAL); | ||
| 5593 | + rv = nghttp2_session_add_rst_stream( | ||
| 5594 | + session, iframe->frame.hd.stream_id, NGHTTP2_INTERNAL_ERROR); | ||
| 5592 | 5595 | if (nghttp2_is_fatal(rv)) { | |
| 5593 | 5596 | return rv; | |
| 5594 | 5597 | } | |
@@ -6104,8 +6107,8 @@ nghttp2_ssize nghttp2_session_mem_recv2(nghttp2_session *session, | |||
| 6104 | 6107 | } | |
| 6105 | 6108 | ||
| 6106 | 6109 | if (rv == NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE) { | |
| 6107 | - rv = session_handle_invalid_stream2( | ||
| 6108 | - session, iframe->frame.hd.stream_id, NULL, NGHTTP2_ERR_INTERNAL); | ||
| 6110 | + rv = nghttp2_session_add_rst_stream( | ||
| 6111 | + session, iframe->frame.hd.stream_id, NGHTTP2_INTERNAL_ERROR); | ||
| 6109 | 6112 | if (nghttp2_is_fatal(rv)) { | |
| 6110 | 6113 | return rv; | |
| 6111 | 6114 | } | |
@@ -6188,9 +6191,9 @@ nghttp2_ssize nghttp2_session_mem_recv2(nghttp2_session *session, | |||
| 6188 | 6191 | } | |
| 6189 | 6192 | ||
| 6190 | 6193 | if (rv == NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE) { | |
| 6191 | - rv = session_handle_invalid_stream2( | ||
| 6192 | - session, iframe->frame.push_promise.promised_stream_id, NULL, | ||
| 6193 | - NGHTTP2_ERR_INTERNAL); | ||
| 6194 | + rv = nghttp2_session_add_rst_stream( | ||
| 6195 | + session, iframe->frame.push_promise.promised_stream_id, | ||
| 6196 | + NGHTTP2_INTERNAL_ERROR); | ||
| 6194 | 6197 | if (nghttp2_is_fatal(rv)) { | |
| 6195 | 6198 | return rv; | |
| 6196 | 6199 | } | |
@@ -6368,12 +6371,12 @@ nghttp2_ssize nghttp2_session_mem_recv2(nghttp2_session *session, | |||
| 6368 | 6371 | iframe->payloadleft -= hd_proclen; | |
| 6369 | 6372 | ||
| 6370 | 6373 | /* Use promised stream ID for PUSH_PROMISE */ | |
| 6371 | - rv = session_handle_invalid_stream2( | ||
| 6374 | + rv = nghttp2_session_add_rst_stream( | ||
| 6372 | 6375 | session, | |
| 6373 | 6376 | iframe->frame.hd.type == NGHTTP2_PUSH_PROMISE | |
| 6374 | 6377 | ? iframe->frame.push_promise.promised_stream_id | |
| 6375 | 6378 | : iframe->frame.hd.stream_id, | |
| 6376 | - NULL, NGHTTP2_ERR_INTERNAL); | ||
| 6379 | + NGHTTP2_INTERNAL_ERROR); | ||
| 6377 | 6380 | if (nghttp2_is_fatal(rv)) { | |
| 6378 | 6381 | return rv; | |
| 6379 | 6382 | } | |
@@ -6420,10 +6423,6 @@ nghttp2_ssize nghttp2_session_mem_recv2(nghttp2_session *session, | |||
| 6420 | 6423 | if (nghttp2_is_fatal(rv)) { | |
| 6421 | 6424 | return rv; | |
| 6422 | 6425 | } | |
| 6423 | - | ||
| 6424 | - if (iframe->state == NGHTTP2_IB_IGN_ALL) { | ||
| 6425 | - return (nghttp2_ssize)inlen; | ||
| 6426 | - } | ||
| 6427 | 6426 | } | |
| 6428 | 6427 | session_inbound_frame_reset(session); | |
| 6429 | 6428 | ||
@@ -6649,10 +6648,6 @@ nghttp2_ssize nghttp2_session_mem_recv2(nghttp2_session *session, | |||
| 6649 | 6648 | if (nghttp2_is_fatal(rv)) { | |
| 6650 | 6649 | return rv; | |
| 6651 | 6650 | } | |
| 6652 | - | ||
| 6653 | - if (iframe->state == NGHTTP2_IB_IGN_ALL) { | ||
| 6654 | - return (nghttp2_ssize)inlen; | ||
| 6655 | - } | ||
| 6656 | 6651 | } | |
| 6657 | 6652 | ||
| 6658 | 6653 | busy = 1; | |
@@ -6725,10 +6720,6 @@ nghttp2_ssize nghttp2_session_mem_recv2(nghttp2_session *session, | |||
| 6725 | 6720 | return rv; | |
| 6726 | 6721 | } | |
| 6727 | 6722 | ||
| 6728 | - if (iframe->state == NGHTTP2_IB_IGN_ALL) { | ||
| 6729 | - return (nghttp2_ssize)inlen; | ||
| 6730 | - } | ||
| 6731 | - | ||
| 6732 | 6723 | data_readlen = | |
| 6733 | 6724 | inbound_frame_effective_readlen(iframe, iframe->payloadleft, readlen); | |
| 6734 | 6725 | ||
@@ -6758,13 +6749,28 @@ nghttp2_ssize nghttp2_session_mem_recv2(nghttp2_session *session, | |||
| 6758 | 6749 | if (data_readlen > 0) { | |
| 6759 | 6750 | if (session_enforce_http_messaging(session)) { | |
| 6760 | 6751 | if (nghttp2_http_on_data_chunk(stream, (size_t)data_readlen) != 0) { | |
| 6761 | - rv = nghttp2_session_terminate_session(session, | ||
| 6762 | - NGHTTP2_PROTOCOL_ERROR); | ||
| 6752 | + if (session->opt_flags & NGHTTP2_OPTMASK_NO_AUTO_WINDOW_UPDATE) { | ||
| 6753 | + /* Consume all data for connection immediately here */ | ||
| 6754 | + rv = session_update_connection_consumed_size( | ||
| 6755 | + session, (size_t)data_readlen); | ||
| 6756 | + | ||
| 6757 | + if (nghttp2_is_fatal(rv)) { | ||
| 6758 | + return rv; | ||
| 6759 | + } | ||
| 6760 | + | ||
| 6761 | + if (iframe->state == NGHTTP2_IB_IGN_DATA) { | ||
| 6762 | + return (nghttp2_ssize)inlen; | ||
| 6763 | + } | ||
| 6764 | + } | ||
| 6765 | + | ||
| 6766 | + rv = nghttp2_session_add_rst_stream( | ||
| 6767 | + session, iframe->frame.hd.stream_id, NGHTTP2_PROTOCOL_ERROR); | ||
| 6763 | 6768 | if (nghttp2_is_fatal(rv)) { | |
| 6764 | 6769 | return rv; | |
| 6765 | 6770 | } | |
| 6766 | - | ||
| 6767 | - return (nghttp2_ssize)inlen; | ||
| 6771 | + busy = 1; | ||
| 6772 | + iframe->state = NGHTTP2_IB_IGN_DATA; | ||
| 6773 | + break; | ||
| 6768 | 6774 | } | |
| 6769 | 6775 | } | |
| 6770 | 6776 | if (session->callbacks.on_data_chunk_recv_callback) { | |
@@ -6791,10 +6797,6 @@ nghttp2_ssize nghttp2_session_mem_recv2(nghttp2_session *session, | |||
| 6791 | 6797 | return rv; | |
| 6792 | 6798 | } | |
| 6793 | 6799 | ||
| 6794 | - if (iframe->state == NGHTTP2_IB_IGN_ALL) { | ||
| 6795 | - return (nghttp2_ssize)inlen; | ||
| 6796 | - } | ||
| 6797 | - | ||
| 6798 | 6800 | session_inbound_frame_reset(session); | |
| 6799 | 6801 | ||
| 6800 | 6802 | break; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments