diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index 97cdd1ba..f390621d 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -4684,12 +4684,8 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, if (iframe->sbuf.pos[3] != NGHTTP2_SETTINGS || (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_PAYLOAD; + iframe->state = NGHTTP2_IB_IGN_ALL; rv = nghttp2_session_terminate_session_with_reason( 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; } - break; + return inlen; } 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); break; + case NGHTTP2_IB_IGN_ALL: + return inlen; } if (!busy && in == last) { diff --git a/lib/nghttp2_session.h b/lib/nghttp2_session.h index 651a36ff..c9422a5d 100644 --- a/lib/nghttp2_session.h +++ b/lib/nghttp2_session.h @@ -81,7 +81,8 @@ typedef enum { NGHTTP2_IB_IGN_CONTINUATION, NGHTTP2_IB_READ_PAD_DATA, NGHTTP2_IB_READ_DATA, - NGHTTP2_IB_IGN_DATA + NGHTTP2_IB_IGN_DATA, + NGHTTP2_IB_IGN_ALL, } nghttp2_inbound_state; #define NGHTTP2_INBOUND_NUM_IV 7 diff --git a/tests/nghttp2_session_test.c b/tests/nghttp2_session_test.c index 09f98a70..be6016d6 100644 --- a/tests/nghttp2_session_test.c +++ b/tests/nghttp2_session_test.c @@ -6581,15 +6581,15 @@ void test_nghttp2_session_recv_client_preface(void) { CU_ASSERT(rv == NGHTTP2_CLIENT_CONNECTION_PREFACE_LEN); 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_pack_frame_hd(buf, &ping_frame.ping.hd); rv = nghttp2_session_mem_recv(session, buf, NGHTTP2_FRAME_HDLEN); CU_ASSERT(NGHTTP2_FRAME_HDLEN == rv); - CU_ASSERT(NGHTTP2_IB_IGN_PAYLOAD == session->iframe.state); - CU_ASSERT(8 == session->iframe.payloadleft); + CU_ASSERT(NGHTTP2_IB_IGN_ALL == session->iframe.state); + CU_ASSERT(0 == session->iframe.payloadleft); nghttp2_frame_ping_free(&ping_frame.ping);