Early termination if stream is not found

Add this check in nghttp2_submit_{priority, window_update, data,
push_promise}.
This commit is contained in:
Tatsuhiro Tsujikawa 2013-08-10 00:02:24 +09:00
parent 80bacd0a54
commit 6ed8a8957b
3 changed files with 23 additions and 11 deletions

View File

@ -1582,6 +1582,8 @@ int nghttp2_submit_headers(nghttp2_session *session, uint8_t flags,
*
* :enum:`NGHTTP2_ERR_NOMEM`
* Out of memory.
* :enum:`NGHTTP2_ERR_STREAM_CLOSED`
* The stream is already closed or does not exist.
*/
int nghttp2_submit_data(nghttp2_session *session, uint8_t flags,
int32_t stream_id,
@ -1600,6 +1602,8 @@ int nghttp2_submit_data(nghttp2_session *session, uint8_t flags,
* Out of memory.
* :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
* The |pri| is negative.
* :enum:`NGHTTP2_ERR_STREAM_CLOSED`
* The stream is already closed or does not exist.
*/
int nghttp2_submit_priority(nghttp2_session *session, int32_t stream_id,
int32_t pri);
@ -1678,6 +1682,8 @@ int nghttp2_submit_settings(nghttp2_session *session,
*
* :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
* The |nv| includes empty name or ``NULL`` value.
* :enum:`NGHTTP2_ERR_STREAM_CLOSED`
* The stream is already closed or does not exist.
* :enum:`NGHTTP2_ERR_NOMEM`
* Out of memory.
*/

View File

@ -118,9 +118,14 @@ int nghttp2_submit_priority(nghttp2_session *session, int32_t stream_id,
{
int r;
nghttp2_frame *frame;
nghttp2_stream *stream;
if(pri < 0) {
return NGHTTP2_ERR_INVALID_ARGUMENT;
}
stream = nghttp2_session_get_stream(session, stream_id);
if(stream == NULL) {
return NGHTTP2_ERR_STREAM_CLOSED;
}
frame = malloc(sizeof(nghttp2_frame));
if(frame == NULL) {
return NGHTTP2_ERR_NOMEM;
@ -134,10 +139,7 @@ int nghttp2_submit_priority(nghttp2_session *session, int32_t stream_id,
}
/* Only update priority if the sender is client for now */
if(!session->server) {
nghttp2_stream *stream = nghttp2_session_get_stream(session, stream_id);
if(stream) {
nghttp2_session_reprioritize_stream(session, stream, pri);
}
nghttp2_session_reprioritize_stream(session, stream, pri);
}
return 0;
}
@ -202,6 +204,9 @@ int nghttp2_submit_push_promise(nghttp2_session *session, uint8_t flags,
uint8_t flags_copy;
int r;
if(nghttp2_session_get_stream(session, stream_id) == NULL) {
return NGHTTP2_ERR_STREAM_CLOSED;
}
if(!nghttp2_frame_nv_check_null(nv)) {
return NGHTTP2_ERR_INVALID_ARGUMENT;
}
@ -240,6 +245,8 @@ int nghttp2_submit_window_update(nghttp2_session *session, uint8_t flags,
stream = nghttp2_session_get_stream(session, stream_id);
if(stream) {
stream->local_flow_control = 0;
} else {
return NGHTTP2_ERR_STREAM_CLOSED;
}
}
return nghttp2_session_add_window_update(session, flags, stream_id, 0);
@ -331,6 +338,10 @@ int nghttp2_submit_data(nghttp2_session *session, uint8_t flags,
int r;
nghttp2_data *data_frame;
uint8_t nflags = 0;
if(nghttp2_session_get_stream(session, stream_id) == NULL) {
return NGHTTP2_ERR_STREAM_CLOSED;
}
data_frame = malloc(sizeof(nghttp2_frame));
if(data_frame == NULL) {
return NGHTTP2_ERR_NOMEM;

View File

@ -3073,14 +3073,9 @@ void test_nghttp2_session_on_ctrl_not_send(void)
CU_ASSERT(NGHTTP2_HEADERS == user_data.not_sent_frame_type);
CU_ASSERT(NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE == user_data.not_sent_error);
session->next_stream_id = 1;
user_data.frame_not_send_cb_called = 0;
/* Send PRIORITY to stream ID = 1 which does not exist */
CU_ASSERT(0 == nghttp2_submit_priority(session, 1, 0));
CU_ASSERT(0 == nghttp2_session_send(session));
CU_ASSERT(1 == user_data.frame_not_send_cb_called);
CU_ASSERT(NGHTTP2_PRIORITY == user_data.not_sent_frame_type);
CU_ASSERT(NGHTTP2_ERR_STREAM_CLOSED == user_data.not_sent_error);
CU_ASSERT(NGHTTP2_ERR_STREAM_CLOSED ==
nghttp2_submit_priority(session, 1, 0));
user_data.frame_not_send_cb_called = 0;
/* Send GOAWAY */