From b08d5b1975656f705585015cdf0ad72d06b73f56 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 24 Nov 2015 22:33:06 +0900 Subject: [PATCH] Explicitly treat stream_id 0 as error in nghttp2_session_change_stream_priority --- lib/includes/nghttp2/nghttp2.h | 4 ++-- lib/nghttp2_session.c | 2 +- tests/nghttp2_session_test.c | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/includes/nghttp2/nghttp2.h b/lib/includes/nghttp2/nghttp2.h index 94b07753..47ca79a5 100644 --- a/lib/includes/nghttp2/nghttp2.h +++ b/lib/includes/nghttp2/nghttp2.h @@ -2879,8 +2879,8 @@ NGHTTP2_EXTERN int nghttp2_session_consume_stream(nghttp2_session *session, * :enum:`NGHTTP2_ERR_NOMEM` * Out of memory. * :enum:`NGHTTP2_ERR_INVALID_ARGUMENT` - * Attempted to depend on itself; no stream exist for the given - * |stream_id|. + * Attempted to depend on itself; or no stream exist for the given + * |stream_id|; or |stream_id| is 0 */ NGHTTP2_EXTERN int nghttp2_session_change_stream_priority(nghttp2_session *session, diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index 7f1e883e..473b3807 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -6789,7 +6789,7 @@ int nghttp2_session_change_stream_priority( nghttp2_stream *stream; nghttp2_priority_spec pri_spec_copy; - if (stream_id == pri_spec->stream_id) { + if (stream_id == 0 || stream_id == pri_spec->stream_id) { return NGHTTP2_ERR_INVALID_ARGUMENT; } diff --git a/tests/nghttp2_session_test.c b/tests/nghttp2_session_test.c index 3b85e743..45f61d33 100644 --- a/tests/nghttp2_session_test.c +++ b/tests/nghttp2_session_test.c @@ -8379,6 +8379,10 @@ void test_nghttp2_session_change_stream_priority(void) { rv = nghttp2_session_change_stream_priority(session, 1, &pri_spec); CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + /* It is an error to change priority of root stream (0) */ + rv = nghttp2_session_change_stream_priority(session, 0, &pri_spec); + CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + nghttp2_session_del(session); }