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,17 +455,16 @@ 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 ) {
469
- if (nghttp3_client_stream_bidi (stream_id )) {
470
- if (stream -> rx .hstate == NGHTTP3_HTTP_STATE_NONE ) {
471
- stream -> rx .hstate = NGHTTP3_HTTP_STATE_REQ_INITIAL ;
472
- stream -> tx .hstate = NGHTTP3_HTTP_STATE_REQ_INITIAL ;
473
- }
474
- }
463
+ assert (nghttp3_client_stream_bidi (stream_id ) ||
464
+ nghttp3_client_stream_uni (stream_id ));
465
+ } else {
466
+ assert (nghttp3_client_stream_bidi (stream_id ) ||
467
+ nghttp3_server_stream_uni (stream_id ));
475
468
}
476
469
477
470
if (srclen == 0 && !fin ) {
@@ -608,6 +601,9 @@ nghttp3_ssize nghttp3_conn_read_uni(nghttp3_conn *conn, nghttp3_stream *stream,
608
601
break ;
609
602
case NGHTTP3_STREAM_TYPE_UNKNOWN :
610
603
nconsumed = (nghttp3_ssize )srclen ;
604
+ if (fin ) {
605
+ break ;
606
+ }
611
607
612
608
rv = conn_call_stop_sending (conn , stream , NGHTTP3_H3_STREAM_CREATION_ERROR );
613
609
if (rv != 0 ) {
@@ -1792,6 +1788,8 @@ conn_on_priority_update_stream(nghttp3_conn *conn,
1792
1788
1793
1789
stream -> node .pri = fr -> pri ;
1794
1790
stream -> flags |= NGHTTP3_STREAM_FLAG_PRIORITY_UPDATE_RECVED ;
1791
+ stream -> rx .hstate = NGHTTP3_HTTP_STATE_REQ_INITIAL ;
1792
+ stream -> tx .hstate = NGHTTP3_HTTP_STATE_REQ_INITIAL ;
1795
1793
1796
1794
return 0 ;
1797
1795
}
@@ -1836,7 +1834,7 @@ int nghttp3_conn_create_stream(nghttp3_conn *conn, nghttp3_stream **pstream,
1836
1834
nghttp3_stream * stream ;
1837
1835
int rv ;
1838
1836
nghttp3_stream_callbacks callbacks = {
1839
- conn_stream_acked_data ,
1837
+ . acked_data = conn_stream_acked_data ,
1840
1838
};
1841
1839
1842
1840
rv = nghttp3_stream_new (& stream , stream_id , & callbacks ,
@@ -1874,6 +1872,8 @@ int nghttp3_conn_bind_control_stream(nghttp3_conn *conn, int64_t stream_id) {
1874
1872
nghttp3_frame_entry frent ;
1875
1873
int rv ;
1876
1874
1875
+ assert (stream_id >= 0 );
1876
+ assert (stream_id <= (int64_t )NGHTTP3_MAX_VARINT );
1877
1877
assert (!conn -> server || nghttp3_server_stream_uni (stream_id ));
1878
1878
assert (conn -> server || nghttp3_client_stream_uni (stream_id ));
1879
1879
@@ -1906,6 +1906,10 @@ int nghttp3_conn_bind_qpack_streams(nghttp3_conn *conn, int64_t qenc_stream_id,
1906
1906
nghttp3_stream * stream ;
1907
1907
int rv ;
1908
1908
1909
+ assert (qenc_stream_id >= 0 );
1910
+ assert (qenc_stream_id <= (int64_t )NGHTTP3_MAX_VARINT );
1911
+ assert (qdec_stream_id >= 0 );
1912
+ assert (qdec_stream_id <= (int64_t )NGHTTP3_MAX_VARINT );
1909
1913
assert (!conn -> server || nghttp3_server_stream_uni (qenc_stream_id ));
1910
1914
assert (!conn -> server || nghttp3_server_stream_uni (qdec_stream_id ));
1911
1915
assert (conn -> server || nghttp3_client_stream_uni (qenc_stream_id ));
@@ -2194,13 +2198,11 @@ int nghttp3_conn_submit_request(nghttp3_conn *conn, int64_t stream_id,
2194
2198
assert (!conn -> server );
2195
2199
assert (conn -> tx .qenc );
2196
2200
2201
+ assert (stream_id >= 0 );
2202
+ assert (stream_id <= (int64_t )NGHTTP3_MAX_VARINT );
2197
2203
assert (nghttp3_client_stream_bidi (stream_id ));
2198
2204
2199
- /* TODO Should we check that stream_id is client stream_id? */
2200
2205
/* TODO Check GOAWAY last stream ID */
2201
- if (nghttp3_stream_uni (stream_id )) {
2202
- return NGHTTP3_ERR_INVALID_ARGUMENT ;
2203
- }
2204
2206
2205
2207
if (conn -> flags & NGHTTP3_CONN_FLAG_GOAWAY_RECVED ) {
2206
2208
return NGHTTP3_ERR_CONN_CLOSING ;
@@ -2454,6 +2456,9 @@ int nghttp3_conn_close_stream(nghttp3_conn *conn, int64_t stream_id,
2454
2456
int nghttp3_conn_shutdown_stream_read (nghttp3_conn * conn , int64_t stream_id ) {
2455
2457
nghttp3_stream * stream ;
2456
2458
2459
+ assert (stream_id >= 0 );
2460
+ assert (stream_id <= (int64_t )NGHTTP3_MAX_VARINT );
2461
+
2457
2462
if (!nghttp3_client_stream_bidi (stream_id )) {
2458
2463
return 0 ;
2459
2464
}
@@ -2515,6 +2520,9 @@ uint64_t nghttp3_conn_get_frame_payload_left(nghttp3_conn *conn,
2515
2520
nghttp3_stream * stream ;
2516
2521
int uni = 0 ;
2517
2522
2523
+ assert (stream_id >= 0 );
2524
+ assert (stream_id <= (int64_t )NGHTTP3_MAX_VARINT );
2525
+
2518
2526
if (!nghttp3_client_stream_bidi (stream_id )) {
2519
2527
uni = conn_remote_stream_uni (conn , stream_id );
2520
2528
if (!uni ) {
@@ -2542,6 +2550,8 @@ int nghttp3_conn_get_stream_priority_versioned(nghttp3_conn *conn,
2542
2550
(void )pri_version ;
2543
2551
2544
2552
assert (conn -> server );
2553
+ assert (stream_id >= 0 );
2554
+ assert (stream_id <= (int64_t )NGHTTP3_MAX_VARINT );
2545
2555
2546
2556
if (!nghttp3_client_stream_bidi (stream_id )) {
2547
2557
return NGHTTP3_ERR_INVALID_ARGUMENT ;
@@ -2566,6 +2576,8 @@ int nghttp3_conn_set_client_stream_priority(nghttp3_conn *conn,
2566
2576
uint8_t * buf = NULL ;
2567
2577
2568
2578
assert (!conn -> server );
2579
+ assert (stream_id >= 0 );
2580
+ assert (stream_id <= (int64_t )NGHTTP3_MAX_VARINT );
2569
2581
2570
2582
if (!nghttp3_client_stream_bidi (stream_id )) {
2571
2583
return NGHTTP3_ERR_INVALID_ARGUMENT ;
@@ -2603,6 +2615,8 @@ int nghttp3_conn_set_server_stream_priority_versioned(nghttp3_conn *conn,
2603
2615
assert (conn -> server );
2604
2616
assert (pri -> urgency < NGHTTP3_URGENCY_LEVELS );
2605
2617
assert (pri -> inc == 0 || pri -> inc == 1 );
2618
+ assert (stream_id >= 0 );
2619
+ assert (stream_id <= (int64_t )NGHTTP3_MAX_VARINT );
2606
2620
2607
2621
if (!nghttp3_client_stream_bidi (stream_id )) {
2608
2622
return NGHTTP3_ERR_INVALID_ARGUMENT ;
0 commit comments