Ignore all incoming bytes when first SETTINGS is not received

This commit is contained in:
Tatsuhiro Tsujikawa 2015-02-15 01:20:10 +09:00
parent 58d3b5b4a0
commit 9c30211da9
3 changed files with 9 additions and 10 deletions

View File

@ -4684,12 +4684,8 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in,
if (iframe->sbuf.pos[3] != NGHTTP2_SETTINGS || if (iframe->sbuf.pos[3] != NGHTTP2_SETTINGS ||
(iframe->sbuf.pos[4] & NGHTTP2_FLAG_ACK)) { (iframe->sbuf.pos[4] & NGHTTP2_FLAG_ACK)) {
nghttp2_frame_unpack_frame_hd(&iframe->frame.hd, iframe->sbuf.pos);
iframe->payloadleft = iframe->frame.hd.length;
busy = 1; iframe->state = NGHTTP2_IB_IGN_ALL;
iframe->state = NGHTTP2_IB_IGN_PAYLOAD;
rv = nghttp2_session_terminate_session_with_reason( rv = nghttp2_session_terminate_session_with_reason(
session, NGHTTP2_PROTOCOL_ERROR, "SETTINGS expected"); session, NGHTTP2_PROTOCOL_ERROR, "SETTINGS expected");
@ -4698,7 +4694,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in,
return rv; return rv;
} }
break; return inlen;
} }
iframe->state = NGHTTP2_IB_READ_HEAD; iframe->state = NGHTTP2_IB_READ_HEAD;
@ -5649,6 +5645,8 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in,
session_inbound_frame_reset(session); session_inbound_frame_reset(session);
break; break;
case NGHTTP2_IB_IGN_ALL:
return inlen;
} }
if (!busy && in == last) { if (!busy && in == last) {

View File

@ -81,7 +81,8 @@ typedef enum {
NGHTTP2_IB_IGN_CONTINUATION, NGHTTP2_IB_IGN_CONTINUATION,
NGHTTP2_IB_READ_PAD_DATA, NGHTTP2_IB_READ_PAD_DATA,
NGHTTP2_IB_READ_DATA, NGHTTP2_IB_READ_DATA,
NGHTTP2_IB_IGN_DATA NGHTTP2_IB_IGN_DATA,
NGHTTP2_IB_IGN_ALL,
} nghttp2_inbound_state; } nghttp2_inbound_state;
#define NGHTTP2_INBOUND_NUM_IV 7 #define NGHTTP2_INBOUND_NUM_IV 7

View File

@ -6581,15 +6581,15 @@ void test_nghttp2_session_recv_client_preface(void) {
CU_ASSERT(rv == NGHTTP2_CLIENT_CONNECTION_PREFACE_LEN); CU_ASSERT(rv == NGHTTP2_CLIENT_CONNECTION_PREFACE_LEN);
CU_ASSERT(NGHTTP2_IB_READ_FIRST_SETTINGS == session->iframe.state); CU_ASSERT(NGHTTP2_IB_READ_FIRST_SETTINGS == session->iframe.state);
/* Receiving PING is error */ /* Receiving PING is error because we want SETTINGS. */
nghttp2_frame_ping_init(&ping_frame.ping, NGHTTP2_FLAG_NONE, NULL); nghttp2_frame_ping_init(&ping_frame.ping, NGHTTP2_FLAG_NONE, NULL);
nghttp2_frame_pack_frame_hd(buf, &ping_frame.ping.hd); nghttp2_frame_pack_frame_hd(buf, &ping_frame.ping.hd);
rv = nghttp2_session_mem_recv(session, buf, NGHTTP2_FRAME_HDLEN); rv = nghttp2_session_mem_recv(session, buf, NGHTTP2_FRAME_HDLEN);
CU_ASSERT(NGHTTP2_FRAME_HDLEN == rv); CU_ASSERT(NGHTTP2_FRAME_HDLEN == rv);
CU_ASSERT(NGHTTP2_IB_IGN_PAYLOAD == session->iframe.state); CU_ASSERT(NGHTTP2_IB_IGN_ALL == session->iframe.state);
CU_ASSERT(8 == session->iframe.payloadleft); CU_ASSERT(0 == session->iframe.payloadleft);
nghttp2_frame_ping_free(&ping_frame.ping); nghttp2_frame_ping_free(&ping_frame.ping);