diff --git a/lib/includes/nghttp2/nghttp2.h b/lib/includes/nghttp2/nghttp2.h index 25a152d6..ff6ed7ae 100644 --- a/lib/includes/nghttp2/nghttp2.h +++ b/lib/includes/nghttp2/nghttp2.h @@ -783,7 +783,7 @@ typedef ssize_t (*nghttp2_recv_callback) * The implementation of this function must return 0 if it * succeeds. If nonzero is returned, it is treated as fatal error and * `nghttp2_session_recv()` and `nghttp2_session_send()` functions - * return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. + * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. */ typedef int (*nghttp2_on_frame_recv_callback) (nghttp2_session *session, nghttp2_frame *frame, void *user_data); @@ -796,8 +796,13 @@ typedef int (*nghttp2_on_frame_recv_callback) * :enum:`nghttp2_error_code` and indicates the error. When this * callback function is invoked, the library automatically submits * either RST_STREAM or GOAWAY frame. + * + * The implementation of this function must return 0 if it + * succeeds. If nonzero is returned, it is treated as fatal error and + * `nghttp2_session_recv()` and `nghttp2_session_send()` functions + * immediately return :enum:`NGHTTP2_ERR_CALLBACK_FAILURE`. */ -typedef void (*nghttp2_on_invalid_frame_recv_callback) +typedef int (*nghttp2_on_invalid_frame_recv_callback) (nghttp2_session *session, nghttp2_frame *frame, nghttp2_error_code error_code, void *user_data); diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index 60d459c4..e2345d95 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -1649,8 +1649,10 @@ static int nghttp2_session_handle_invalid_stream return r; } if(session->callbacks.on_invalid_frame_recv_callback) { - session->callbacks.on_invalid_frame_recv_callback - (session, frame, error_code, session->user_data); + if(session->callbacks.on_invalid_frame_recv_callback + (session, frame, error_code, session->user_data) != 0) { + return NGHTTP2_ERR_CALLBACK_FAILURE; + } } return 0; } @@ -1664,8 +1666,10 @@ static int nghttp2_session_handle_invalid_connection nghttp2_error_code error_code) { if(session->callbacks.on_invalid_frame_recv_callback) { - session->callbacks.on_invalid_frame_recv_callback - (session, frame, error_code, session->user_data); + if(session->callbacks.on_invalid_frame_recv_callback + (session, frame, error_code, session->user_data) != 0) { + return NGHTTP2_ERR_CALLBACK_FAILURE; + } } return nghttp2_session_fail_session(session, error_code); } @@ -2254,8 +2258,10 @@ int nghttp2_session_on_push_promise_received(nghttp2_session *session, } } else { if(session->callbacks.on_invalid_frame_recv_callback) { - session->callbacks.on_invalid_frame_recv_callback - (session, frame, NGHTTP2_PROTOCOL_ERROR, session->user_data); + if(session->callbacks.on_invalid_frame_recv_callback + (session, frame, NGHTTP2_PROTOCOL_ERROR, session->user_data) != 0) { + return NGHTTP2_ERR_CALLBACK_FAILURE; + } } return nghttp2_session_add_rst_stream (session, diff --git a/src/app_helper.cc b/src/app_helper.cc index 562a9162..73679f01 100644 --- a/src/app_helper.cc +++ b/src/app_helper.cc @@ -333,7 +333,7 @@ int on_frame_recv_callback return 0; } -void on_invalid_frame_recv_callback +int on_invalid_frame_recv_callback (nghttp2_session *session, nghttp2_frame *frame, nghttp2_error_code error_code, void *user_data) { @@ -341,6 +341,7 @@ void on_invalid_frame_recv_callback printf(" [INVALID; status=%s] recv ", strstatus(error_code)); print_frame(PRINT_RECV, frame); fflush(stdout); + return 0; } namespace { diff --git a/src/app_helper.h b/src/app_helper.h index 1de0b008..ce4487e2 100644 --- a/src/app_helper.h +++ b/src/app_helper.h @@ -42,7 +42,7 @@ void print_nv(char **nv); int on_frame_recv_callback (nghttp2_session *session, nghttp2_frame *frame, void *user_data); -void on_invalid_frame_recv_callback +int on_invalid_frame_recv_callback (nghttp2_session *session, nghttp2_frame *frame, nghttp2_error_code error_code, void *user_data); diff --git a/tests/nghttp2_session_test.c b/tests/nghttp2_session_test.c index 5bc040ab..3d3537f0 100644 --- a/tests/nghttp2_session_test.c +++ b/tests/nghttp2_session_test.c @@ -135,13 +135,14 @@ static int on_frame_recv_callback(nghttp2_session *session, return 0; } -static void on_invalid_frame_recv_callback(nghttp2_session *session, - nghttp2_frame *frame, - nghttp2_error_code error_code, - void *user_data) +static int on_invalid_frame_recv_callback(nghttp2_session *session, + nghttp2_frame *frame, + nghttp2_error_code error_code, + void *user_data) { my_user_data *ud = (my_user_data*)user_data; ++ud->invalid_frame_recv_cb_called; + return 0; } static void on_frame_send_callback(nghttp2_session *session,