@@ -181,6 +181,49 @@ const struct lsquic_stream_if stream_if = {
181181};
182182
183183
184+ struct dummy_hset
185+ {
186+ struct lsxpack_header xhdr ;
187+ char buf [0x100 ];
188+ };
189+
190+
191+ static void *
192+ dummy_create_header_set (void * hsi_ctx , lsquic_stream_t * stream ,
193+ int is_push_promise )
194+ {
195+ return calloc (1 , sizeof (struct dummy_hset ));
196+ }
197+
198+
199+ static struct lsxpack_header *
200+ dummy_prepare_decode (void * hdr_set , struct lsxpack_header * hdr , size_t space )
201+ {
202+ struct dummy_hset * const dummy = hdr_set ;
203+
204+ if (space > sizeof (dummy -> buf ))
205+ return NULL ;
206+
207+ lsxpack_header_prepare_decode (& dummy -> xhdr , dummy -> buf , 0 ,
208+ sizeof (dummy -> buf ));
209+ return & dummy -> xhdr ;
210+ }
211+
212+
213+ static int
214+ dummy_process_header (void * hdr_set , struct lsxpack_header * hdr )
215+ {
216+ return 0 ;
217+ }
218+
219+
220+ static void
221+ dummy_discard_header_set (void * hdr_set )
222+ {
223+ free (hdr_set );
224+ }
225+
226+
184227static size_t
185228read_from_scheduled_packets (lsquic_send_ctl_t * send_ctl , lsquic_stream_id_t stream_id ,
186229 unsigned char * const begin , size_t bufsz , uint64_t first_offset , int * p_fin ,
@@ -1755,6 +1798,78 @@ test_reading_zero_size_data_frame_scenario3 (void)
17551798}
17561799
17571800
1801+ static void
1802+ expect_content_length_not_verified (struct lsxpack_header * header_arr ,
1803+ unsigned count )
1804+ {
1805+ struct test_objs tobjs ;
1806+ struct lsquic_stream * stream ;
1807+ struct lsquic_http_headers headers = { count , header_arr , };
1808+ const unsigned char * p ;
1809+ unsigned char buf [0x400 ];
1810+ const size_t prefix_cap = 32 ;
1811+ size_t prefix_sz = prefix_cap , headers_sz = sizeof (buf ) - prefix_cap ;
1812+ uint64_t compl_off ;
1813+ enum qwh_status qwh ;
1814+
1815+ init_test_ctl_settings (& g_ctl_settings );
1816+
1817+ stream_ctor_flags |= SCF_IETF ;
1818+ init_test_objs (& tobjs , 0x1000 , 0x2000 , 1252 );
1819+ tobjs .hsi_if = (struct lsquic_hset_if ) {
1820+ .hsi_create_header_set = dummy_create_header_set ,
1821+ .hsi_prepare_decode = dummy_prepare_decode ,
1822+ .hsi_process_header = dummy_process_header ,
1823+ .hsi_discard_header_set = dummy_discard_header_set ,
1824+ };
1825+ tobjs .ctor_flags |= SCF_HTTP |SCF_IETF ;
1826+
1827+ stream = new_stream (& tobjs , 0 , 0x1000 );
1828+
1829+ qwh = lsquic_qeh_write_headers (& tobjs .qeh , stream -> id , 0 , & headers ,
1830+ buf + prefix_cap , & prefix_sz , & headers_sz , & compl_off ,
1831+ NULL );
1832+ assert (qwh == QWH_FULL );
1833+
1834+ p = buf + prefix_cap - prefix_sz ;
1835+ assert (LQRHS_DONE == lsquic_qdh_header_in_begin (& tobjs .qdh , stream ,
1836+ prefix_sz + headers_sz , & p ,
1837+ prefix_sz + headers_sz ));
1838+
1839+ assert (!(stream -> sm_bflags & SMBF_VERIFY_CL ));
1840+
1841+ lsquic_stream_destroy (stream );
1842+ deinit_test_objs (& tobjs );
1843+
1844+ stream_ctor_flags &= ~SCF_IETF ;
1845+ }
1846+
1847+
1848+ static void
1849+ test_invalid_content_length_syntax_is_rejected (void )
1850+ {
1851+ struct lsxpack_header plus_arr [] = {
1852+ { XHDR (":status" , "200" ) },
1853+ { XHDR ("content-length" , "+1" ) },
1854+ };
1855+ struct lsxpack_header space_arr [] = {
1856+ { XHDR (":status" , "200" ) },
1857+ { XHDR ("content-length" , " 1" ) },
1858+ };
1859+ struct lsxpack_header empty_arr [] = {
1860+ { XHDR (":status" , "200" ) },
1861+ { XHDR ("content-length" , "" ) },
1862+ };
1863+
1864+ expect_content_length_not_verified (plus_arr ,
1865+ sizeof (plus_arr ) / sizeof (plus_arr [0 ]));
1866+ expect_content_length_not_verified (space_arr ,
1867+ sizeof (space_arr ) / sizeof (space_arr [0 ]));
1868+ expect_content_length_not_verified (empty_arr ,
1869+ sizeof (empty_arr ) / sizeof (empty_arr [0 ]));
1870+ }
1871+
1872+
17581873static void
17591874test_content_length_overrun_blocks_payload_delivery (void )
17601875{
@@ -1872,6 +1987,7 @@ main (int argc, char **argv)
18721987 test_reading_zero_size_data_frame ();
18731988 test_reading_zero_size_data_frame_scenario2 ();
18741989 test_reading_zero_size_data_frame_scenario3 ();
1990+ test_invalid_content_length_syntax_is_rejected ();
18751991 test_content_length_overrun_blocks_payload_delivery ();
18761992 break ;
18771993 default :
@@ -1892,6 +2008,7 @@ main (int argc, char **argv)
18922008 test_reading_zero_size_data_frame ();
18932009 test_reading_zero_size_data_frame_scenario2 ();
18942010 test_reading_zero_size_data_frame_scenario3 ();
2011+ test_invalid_content_length_syntax_is_rejected ();
18952012 test_content_length_overrun_blocks_payload_delivery ();
18962013 }
18972014
0 commit comments