From 37944253d251f6e89f6f5fb87df73bc763c68662 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 21 Feb 2012 22:04:24 +0900 Subject: [PATCH] Ensure read_callback is non-NULL for response bodies. --- lib/spdylay_submit.c | 4 ++-- tests/main.c | 2 ++ tests/spdylay_session_test.c | 21 +++++++++++++++++++++ tests/spdylay_session_test.h | 1 + 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/spdylay_submit.c b/lib/spdylay_submit.c index d3d7e34f..061af3d7 100644 --- a/lib/spdylay_submit.c +++ b/lib/spdylay_submit.c @@ -53,7 +53,7 @@ int spdylay_submit_response(spdylay_session *session, char **nv_copy; uint8_t flags = 0; spdylay_data_provider *data_prd_copy = NULL; - if(data_prd) { + if(data_prd != NULL && data_prd->read_callback != NULL) { data_prd_copy = malloc(sizeof(spdylay_data_provider)); if(data_prd_copy == NULL) { return SPDYLAY_ERR_NOMEM; @@ -73,7 +73,7 @@ int spdylay_submit_response(spdylay_session *session, } spdylay_frame_nv_downcase(nv_copy); spdylay_frame_nv_sort(nv_copy); - if(data_prd == NULL) { + if(data_prd_copy == NULL) { flags |= SPDYLAY_FLAG_FIN; } spdylay_frame_syn_reply_init(&frame->syn_reply, flags, stream_id, diff --git a/tests/main.c b/tests/main.c index d1c94c71..0997a6ab 100644 --- a/tests/main.c +++ b/tests/main.c @@ -85,6 +85,8 @@ int main(int argc, char* argv[]) !CU_add_test(pSuite, "session_send_syn_reply", test_spdylay_session_send_syn_reply) || !CU_add_test(pSuite, "submit_response", test_spdylay_submit_response) || + !CU_add_test(pSuite, "submit_response_without_data", + test_spdylay_submit_response_with_null_data_read_callback) || !CU_add_test(pSuite, "submit_request_with_data", test_spdylay_submit_request_with_data) || !CU_add_test(pSuite, "submit_request_without_data", diff --git a/tests/spdylay_session_test.c b/tests/spdylay_session_test.c index 807534e4..615b41e6 100644 --- a/tests/spdylay_session_test.c +++ b/tests/spdylay_session_test.c @@ -564,6 +564,27 @@ void test_spdylay_submit_response() spdylay_session_del(session); } +void test_spdylay_submit_response_with_null_data_read_callback() +{ + spdylay_session *session; + spdylay_session_callbacks callbacks; + const char *nv[] = { "Version", "HTTP/1.1", NULL }; + spdylay_data_provider data_prd = {{-1}, NULL}; + spdylay_outbound_item *item; + + memset(&callbacks, 0, sizeof(callbacks)); + callbacks.send_callback = null_send_callback; + CU_ASSERT(0 == spdylay_session_server_new(&session, &callbacks, NULL)); + spdylay_session_open_stream(session, 1, SPDYLAY_FLAG_FIN, 3, + SPDYLAY_STREAM_OPENING, NULL); + CU_ASSERT(0 == spdylay_submit_response(session, 1, nv, &data_prd)); + item = spdylay_session_get_next_ob_item(session); + CU_ASSERT(0 == strcmp("version", item->frame->syn_reply.nv[0])); + CU_ASSERT(item->frame->syn_reply.hd.flags & SPDYLAY_FLAG_FIN); + + spdylay_session_del(session); +} + void test_spdylay_submit_request_with_data() { spdylay_session *session; diff --git a/tests/spdylay_session_test.h b/tests/spdylay_session_test.h index 36b438fe..905c0256 100644 --- a/tests/spdylay_session_test.h +++ b/tests/spdylay_session_test.h @@ -34,6 +34,7 @@ void test_spdylay_session_on_syn_reply_received(); void test_spdylay_session_send_syn_stream(); void test_spdylay_session_send_syn_reply(); void test_spdylay_submit_response(); +void test_spdylay_submit_response_with_null_data_read_callback(); void test_spdylay_submit_request_with_data(); void test_spdylay_submit_request_with_null_data_read_callback(); void test_spdylay_session_reply_fail();