39
39
dynamic table capacity that QPACK encoder is willing to use. */
40
40
#define NGHTTP3_QPACK_ENCODER_MAX_DTABLE_CAPACITY 4096
41
41
42
- nghttp3_objalloc_def (chunk , nghttp3_chunk , oplent );
42
+ nghttp3_objalloc_def (chunk , nghttp3_chunk , oplent )
43
43
44
44
/*
45
45
* conn_remote_stream_uni returns nonzero if |stream_id| is remote
@@ -233,12 +233,16 @@ static int conn_new(nghttp3_conn **pconn, int server, int callbacks_version,
233
233
const nghttp3_callbacks * callbacks , int settings_version ,
234
234
const nghttp3_settings * settings , const nghttp3_mem * mem ,
235
235
void * user_data ) {
236
- int rv ;
237
236
nghttp3_conn * conn ;
238
237
size_t i ;
239
238
(void )callbacks_version ;
240
239
(void )settings_version ;
241
240
241
+ assert (settings -> max_field_section_size <= NGHTTP3_VARINT_MAX );
242
+ assert (settings -> qpack_max_dtable_capacity <= NGHTTP3_VARINT_MAX );
243
+ assert (settings -> qpack_encoder_max_dtable_capacity <= NGHTTP3_VARINT_MAX );
244
+ assert (settings -> qpack_blocked_streams <= NGHTTP3_VARINT_MAX );
245
+
242
246
if (mem == NULL ) {
243
247
mem = nghttp3_mem_default ();
244
248
}
@@ -254,18 +258,11 @@ static int conn_new(nghttp3_conn **pconn, int server, int callbacks_version,
254
258
255
259
nghttp3_map_init (& conn -> streams , mem );
256
260
257
- rv =
258
- nghttp3_qpack_decoder_init (& conn -> qdec , settings -> qpack_max_dtable_capacity ,
259
- settings -> qpack_blocked_streams , mem );
260
- if (rv != 0 ) {
261
- goto qdec_init_fail ;
262
- }
261
+ nghttp3_qpack_decoder_init (& conn -> qdec , settings -> qpack_max_dtable_capacity ,
262
+ settings -> qpack_blocked_streams , mem );
263
263
264
- rv = nghttp3_qpack_encoder_init (
265
- & conn -> qenc , settings -> qpack_encoder_max_dtable_capacity , mem );
266
- if (rv != 0 ) {
267
- goto qenc_init_fail ;
268
- }
264
+ nghttp3_qpack_encoder_init (& conn -> qenc ,
265
+ settings -> qpack_encoder_max_dtable_capacity , mem );
269
266
270
267
nghttp3_pq_init (& conn -> qpack_blocked_streams , ricnt_less , mem );
271
268
@@ -291,16 +288,6 @@ static int conn_new(nghttp3_conn **pconn, int server, int callbacks_version,
291
288
* pconn = conn ;
292
289
293
290
return 0 ;
294
-
295
- qenc_init_fail :
296
- nghttp3_qpack_decoder_free (& conn -> qdec );
297
- qdec_init_fail :
298
- nghttp3_map_free (& conn -> streams );
299
- nghttp3_objalloc_free (& conn -> stream_objalloc );
300
- nghttp3_objalloc_free (& conn -> out_chunk_objalloc );
301
- nghttp3_mem_free (mem , conn );
302
-
303
- return rv ;
304
291
}
305
292
306
293
int nghttp3_conn_client_new_versioned (nghttp3_conn * * pconn ,
@@ -399,6 +386,9 @@ nghttp3_ssize nghttp3_conn_read_stream(nghttp3_conn *conn, int64_t stream_id,
399
386
size_t bidi_nproc ;
400
387
int rv ;
401
388
389
+ assert (stream_id >= 0 );
390
+ assert (stream_id <= (int64_t )NGHTTP3_MAX_VARINT );
391
+
402
392
stream = nghttp3_conn_find_stream (conn , stream_id );
403
393
if (stream == NULL ) {
404
394
/* TODO Assert idtr */
@@ -434,6 +424,10 @@ nghttp3_ssize nghttp3_conn_read_stream(nghttp3_conn *conn, int64_t stream_id,
434
424
return rv ;
435
425
}
436
426
}
427
+ } else if (!nghttp3_client_stream_uni (stream_id )) {
428
+ /* server does not expect to receive new server initiated
429
+ bidirectional or unidirectional stream from client. */
430
+ return NGHTTP3_ERR_H3_STREAM_CREATION_ERROR ;
437
431
} else {
438
432
/* unidirectional stream */
439
433
if (srclen == 0 && fin ) {
@@ -448,7 +442,7 @@ nghttp3_ssize nghttp3_conn_read_stream(nghttp3_conn *conn, int64_t stream_id,
448
442
449
443
stream -> rx .hstate = NGHTTP3_HTTP_STATE_REQ_INITIAL ;
450
444
stream -> tx .hstate = NGHTTP3_HTTP_STATE_REQ_INITIAL ;
451
- } else if (nghttp3_stream_uni (stream_id )) {
445
+ } else if (nghttp3_server_stream_uni (stream_id )) {
452
446
if (srclen == 0 && fin ) {
453
447
return 0 ;
454
448
}
@@ -461,8 +455,8 @@ nghttp3_ssize nghttp3_conn_read_stream(nghttp3_conn *conn, int64_t stream_id,
461
455
stream -> rx .hstate = NGHTTP3_HTTP_STATE_RESP_INITIAL ;
462
456
stream -> tx .hstate = NGHTTP3_HTTP_STATE_RESP_INITIAL ;
463
457
} else {
464
- /* client doesn't expect to receive new bidirectional stream
465
- from server. */
458
+ /* client doesn't expect to receive new bidirectional stream or
459
+ client initiated unidirectional stream from server. */
466
460
return NGHTTP3_ERR_H3_STREAM_CREATION_ERROR ;
467
461
}
468
462
} else if (conn -> server ) {
@@ -471,7 +465,12 @@ nghttp3_ssize nghttp3_conn_read_stream(nghttp3_conn *conn, int64_t stream_id,
471
465
stream -> rx .hstate = NGHTTP3_HTTP_STATE_REQ_INITIAL ;
472
466
stream -> tx .hstate = NGHTTP3_HTTP_STATE_REQ_INITIAL ;
473
467
}
468
+ } else {
469
+ assert (nghttp3_client_stream_uni (stream_id ));
474
470
}
471
+ } else {
472
+ assert (nghttp3_client_stream_bidi (stream_id ) ||
473
+ nghttp3_server_stream_uni (stream_id ));
475
474
}
476
475
477
476
if (srclen == 0 && !fin ) {
@@ -608,6 +607,9 @@ nghttp3_ssize nghttp3_conn_read_uni(nghttp3_conn *conn, nghttp3_stream *stream,
608
607
break ;
609
608
case NGHTTP3_STREAM_TYPE_UNKNOWN :
610
609
nconsumed = (nghttp3_ssize )srclen ;
610
+ if (fin ) {
611
+ break ;
612
+ }
611
613
612
614
rv = conn_call_stop_sending (conn , stream , NGHTTP3_H3_STREAM_CREATION_ERROR );
613
615
if (rv != 0 ) {
@@ -1836,7 +1838,7 @@ int nghttp3_conn_create_stream(nghttp3_conn *conn, nghttp3_stream **pstream,
1836
1838
nghttp3_stream * stream ;
1837
1839
int rv ;
1838
1840
nghttp3_stream_callbacks callbacks = {
1839
- conn_stream_acked_data ,
1841
+ . acked_data = conn_stream_acked_data ,
1840
1842
};
1841
1843
1842
1844
rv = nghttp3_stream_new (& stream , stream_id , & callbacks ,
@@ -1874,6 +1876,8 @@ int nghttp3_conn_bind_control_stream(nghttp3_conn *conn, int64_t stream_id) {
1874
1876
nghttp3_frame_entry frent ;
1875
1877
int rv ;
1876
1878
1879
+ assert (stream_id >= 0 );
1880
+ assert (stream_id <= (int64_t )NGHTTP3_MAX_VARINT );
1877
1881
assert (!conn -> server || nghttp3_server_stream_uni (stream_id ));
1878
1882
assert (conn -> server || nghttp3_client_stream_uni (stream_id ));
1879
1883
@@ -1906,6 +1910,10 @@ int nghttp3_conn_bind_qpack_streams(nghttp3_conn *conn, int64_t qenc_stream_id,
1906
1910
nghttp3_stream * stream ;
1907
1911
int rv ;
1908
1912
1913
+ assert (qenc_stream_id >= 0 );
1914
+ assert (qenc_stream_id <= (int64_t )NGHTTP3_MAX_VARINT );
1915
+ assert (qdec_stream_id >= 0 );
1916
+ assert (qdec_stream_id <= (int64_t )NGHTTP3_MAX_VARINT );
1909
1917
assert (!conn -> server || nghttp3_server_stream_uni (qenc_stream_id ));
1910
1918
assert (!conn -> server || nghttp3_server_stream_uni (qdec_stream_id ));
1911
1919
assert (conn -> server || nghttp3_client_stream_uni (qenc_stream_id ));
@@ -2194,13 +2202,11 @@ int nghttp3_conn_submit_request(nghttp3_conn *conn, int64_t stream_id,
2194
2202
assert (!conn -> server );
2195
2203
assert (conn -> tx .qenc );
2196
2204
2205
+ assert (stream_id >= 0 );
2206
+ assert (stream_id <= (int64_t )NGHTTP3_MAX_VARINT );
2197
2207
assert (nghttp3_client_stream_bidi (stream_id ));
2198
2208
2199
- /* TODO Should we check that stream_id is client stream_id? */
2200
2209
/* TODO Check GOAWAY last stream ID */
2201
- if (nghttp3_stream_uni (stream_id )) {
2202
- return NGHTTP3_ERR_INVALID_ARGUMENT ;
2203
- }
2204
2210
2205
2211
if (conn -> flags & NGHTTP3_CONN_FLAG_GOAWAY_RECVED ) {
2206
2212
return NGHTTP3_ERR_CONN_CLOSING ;
@@ -2454,6 +2460,9 @@ int nghttp3_conn_close_stream(nghttp3_conn *conn, int64_t stream_id,
2454
2460
int nghttp3_conn_shutdown_stream_read (nghttp3_conn * conn , int64_t stream_id ) {
2455
2461
nghttp3_stream * stream ;
2456
2462
2463
+ assert (stream_id >= 0 );
2464
+ assert (stream_id <= (int64_t )NGHTTP3_MAX_VARINT );
2465
+
2457
2466
if (!nghttp3_client_stream_bidi (stream_id )) {
2458
2467
return 0 ;
2459
2468
}
@@ -2515,6 +2524,9 @@ uint64_t nghttp3_conn_get_frame_payload_left(nghttp3_conn *conn,
2515
2524
nghttp3_stream * stream ;
2516
2525
int uni = 0 ;
2517
2526
2527
+ assert (stream_id >= 0 );
2528
+ assert (stream_id <= (int64_t )NGHTTP3_MAX_VARINT );
2529
+
2518
2530
if (!nghttp3_client_stream_bidi (stream_id )) {
2519
2531
uni = conn_remote_stream_uni (conn , stream_id );
2520
2532
if (!uni ) {
@@ -2542,6 +2554,8 @@ int nghttp3_conn_get_stream_priority_versioned(nghttp3_conn *conn,
2542
2554
(void )pri_version ;
2543
2555
2544
2556
assert (conn -> server );
2557
+ assert (stream_id >= 0 );
2558
+ assert (stream_id <= (int64_t )NGHTTP3_MAX_VARINT );
2545
2559
2546
2560
if (!nghttp3_client_stream_bidi (stream_id )) {
2547
2561
return NGHTTP3_ERR_INVALID_ARGUMENT ;
@@ -2566,6 +2580,8 @@ int nghttp3_conn_set_client_stream_priority(nghttp3_conn *conn,
2566
2580
uint8_t * buf = NULL ;
2567
2581
2568
2582
assert (!conn -> server );
2583
+ assert (stream_id >= 0 );
2584
+ assert (stream_id <= (int64_t )NGHTTP3_MAX_VARINT );
2569
2585
2570
2586
if (!nghttp3_client_stream_bidi (stream_id )) {
2571
2587
return NGHTTP3_ERR_INVALID_ARGUMENT ;
@@ -2603,6 +2619,8 @@ int nghttp3_conn_set_server_stream_priority_versioned(nghttp3_conn *conn,
2603
2619
assert (conn -> server );
2604
2620
assert (pri -> urgency < NGHTTP3_URGENCY_LEVELS );
2605
2621
assert (pri -> inc == 0 || pri -> inc == 1 );
2622
+ assert (stream_id >= 0 );
2623
+ assert (stream_id <= (int64_t )NGHTTP3_MAX_VARINT );
2606
2624
2607
2625
if (!nghttp3_client_stream_bidi (stream_id )) {
2608
2626
return NGHTTP3_ERR_INVALID_ARGUMENT ;
0 commit comments