From 70c0558443e8faa475896dfd70ef3bf193b31c28 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 10 Oct 2014 21:46:02 +0900 Subject: [PATCH] Set payload length when expected SETTINGS is not received --- lib/nghttp2_session.c | 3 +++ tests/nghttp2_session_test.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index 6c06fdd3..d64a15a3 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -4413,6 +4413,9 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, } if(iframe->sbuf.pos[3] != NGHTTP2_SETTINGS) { + 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; diff --git a/tests/nghttp2_session_test.c b/tests/nghttp2_session_test.c index 19598226..218fba42 100644 --- a/tests/nghttp2_session_test.c +++ b/tests/nghttp2_session_test.c @@ -6477,6 +6477,8 @@ void test_nghttp2_session_recv_client_preface(void) nghttp2_session_callbacks callbacks; nghttp2_option *option; ssize_t rv; + nghttp2_frame ping_frame; + uint8_t buf[16]; memset(&callbacks, 0, sizeof(callbacks)); @@ -6496,6 +6498,18 @@ 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 */ + 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); + + nghttp2_frame_ping_free(&ping_frame.ping); + nghttp2_session_del(session); /* Check bad case */