Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assert stream_id range in public API #295

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions lib/nghttp3_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,9 @@ nghttp3_ssize nghttp3_conn_read_stream(nghttp3_conn *conn, int64_t stream_id,
size_t bidi_nproc;
int rv;

assert(stream_id >= 0);
assert(stream_id <= (int64_t)NGHTTP3_MAX_VARINT);

stream = nghttp3_conn_find_stream(conn, stream_id);
if (stream == NULL) {
/* TODO Assert idtr */
Expand Down Expand Up @@ -1883,6 +1886,8 @@ int nghttp3_conn_bind_control_stream(nghttp3_conn *conn, int64_t stream_id) {
nghttp3_frame_entry frent;
int rv;

assert(stream_id >= 0);
assert(stream_id <= (int64_t)NGHTTP3_MAX_VARINT);
assert(!conn->server || nghttp3_server_stream_uni(stream_id));
assert(conn->server || nghttp3_client_stream_uni(stream_id));

Expand Down Expand Up @@ -1915,6 +1920,10 @@ int nghttp3_conn_bind_qpack_streams(nghttp3_conn *conn, int64_t qenc_stream_id,
nghttp3_stream *stream;
int rv;

assert(qenc_stream_id >= 0);
assert(qenc_stream_id <= (int64_t)NGHTTP3_MAX_VARINT);
assert(qdec_stream_id >= 0);
assert(qdec_stream_id <= (int64_t)NGHTTP3_MAX_VARINT);
assert(!conn->server || nghttp3_server_stream_uni(qenc_stream_id));
assert(!conn->server || nghttp3_server_stream_uni(qdec_stream_id));
assert(conn->server || nghttp3_client_stream_uni(qenc_stream_id));
Expand Down Expand Up @@ -2203,6 +2212,8 @@ int nghttp3_conn_submit_request(nghttp3_conn *conn, int64_t stream_id,
assert(!conn->server);
assert(conn->tx.qenc);

assert(stream_id >= 0);
assert(stream_id <= (int64_t)NGHTTP3_MAX_VARINT);
assert(nghttp3_client_stream_bidi(stream_id));

/* TODO Should we check that stream_id is client stream_id? */
Expand Down Expand Up @@ -2463,6 +2474,9 @@ int nghttp3_conn_close_stream(nghttp3_conn *conn, int64_t stream_id,
int nghttp3_conn_shutdown_stream_read(nghttp3_conn *conn, int64_t stream_id) {
nghttp3_stream *stream;

assert(stream_id >= 0);
assert(stream_id <= (int64_t)NGHTTP3_MAX_VARINT);

if (!nghttp3_client_stream_bidi(stream_id)) {
return 0;
}
Expand Down Expand Up @@ -2524,6 +2538,9 @@ uint64_t nghttp3_conn_get_frame_payload_left(nghttp3_conn *conn,
nghttp3_stream *stream;
int uni = 0;

assert(stream_id >= 0);
assert(stream_id <= (int64_t)NGHTTP3_MAX_VARINT);

if (!nghttp3_client_stream_bidi(stream_id)) {
uni = conn_remote_stream_uni(conn, stream_id);
if (!uni) {
Expand Down Expand Up @@ -2551,6 +2568,8 @@ int nghttp3_conn_get_stream_priority_versioned(nghttp3_conn *conn,
(void)pri_version;

assert(conn->server);
assert(stream_id >= 0);
assert(stream_id <= (int64_t)NGHTTP3_MAX_VARINT);

if (!nghttp3_client_stream_bidi(stream_id)) {
return NGHTTP3_ERR_INVALID_ARGUMENT;
Expand All @@ -2575,6 +2594,8 @@ int nghttp3_conn_set_client_stream_priority(nghttp3_conn *conn,
uint8_t *buf = NULL;

assert(!conn->server);
assert(stream_id >= 0);
assert(stream_id <= (int64_t)NGHTTP3_MAX_VARINT);

if (!nghttp3_client_stream_bidi(stream_id)) {
return NGHTTP3_ERR_INVALID_ARGUMENT;
Expand Down Expand Up @@ -2612,6 +2633,8 @@ int nghttp3_conn_set_server_stream_priority_versioned(nghttp3_conn *conn,
assert(conn->server);
assert(pri->urgency < NGHTTP3_URGENCY_LEVELS);
assert(pri->inc == 0 || pri->inc == 1);
assert(stream_id >= 0);
assert(stream_id <= (int64_t)NGHTTP3_MAX_VARINT);

if (!nghttp3_client_stream_bidi(stream_id)) {
return NGHTTP3_ERR_INVALID_ARGUMENT;
Expand Down
9 changes: 9 additions & 0 deletions lib/nghttp3_qpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,9 @@ int nghttp3_qpack_encoder_encode(nghttp3_qpack_encoder *encoder,
int blocked_stream;
nghttp3_qpack_stream *stream;

assert(stream_id >= 0);
assert(stream_id <= (int64_t)NGHTTP3_MAX_VARINT);

if (encoder->ctx.bad) {
return NGHTTP3_ERR_QPACK_FATAL;
}
Expand Down Expand Up @@ -3852,6 +3855,9 @@ int nghttp3_qpack_decoder_cancel_stream(nghttp3_qpack_decoder *decoder,
uint8_t *p;
int rv;

assert(stream_id >= 0);
assert(stream_id <= (int64_t)NGHTTP3_MAX_VARINT);

if (qpack_decoder_dbuf_overflow(decoder)) {
return NGHTTP3_ERR_QPACK_FATAL;
}
Expand Down Expand Up @@ -4132,6 +4138,9 @@ int nghttp3_qpack_stream_context_new(nghttp3_qpack_stream_context **psctx,
const nghttp3_mem *mem) {
nghttp3_qpack_stream_context *p;

assert(stream_id >= 0);
assert(stream_id <= (int64_t)NGHTTP3_MAX_VARINT);

p = nghttp3_mem_malloc(mem, sizeof(nghttp3_qpack_stream_context));
if (p == NULL) {
return NGHTTP3_ERR_NOMEM;
Expand Down
Loading