@@ -4389,12 +4389,20 @@ uint8_t * picoquic_format_connection_close_frame(picoquic_cnx_t* cnx,
43894389
43904390const uint8_t * picoquic_decode_connection_close_frame (picoquic_cnx_t * cnx , const uint8_t * bytes , const uint8_t * bytes_max )
43914391{
4392- bytes = picoquic_frames_varint_decode ( bytes + 1 , bytes_max , & cnx -> remote_error ) ;
4392+ uint64_t reason_length = 0 ;
43934393
4394- if (bytes == NULL ||
4395- (bytes = picoquic_frames_varint_skip (bytes , bytes_max )) == NULL ||
4396- (bytes = picoquic_frames_length_data_skip (bytes , bytes_max )) == NULL )
4397- {
4394+ if ((bytes = picoquic_frames_varint_decode (bytes + 1 , bytes_max , & cnx -> remote_error )) != NULL &&
4395+ (bytes = picoquic_frames_varint_skip (bytes , bytes_max )) != NULL &&
4396+ (bytes = picoquic_frames_varint_decode (bytes , bytes_max , & reason_length )) != NULL ){
4397+ const uint8_t * first_byte = bytes ;
4398+ if (reason_length != 0 &&
4399+ (bytes = picoquic_frames_fixed_skip (bytes , bytes_max , reason_length )) != NULL &&
4400+ cnx -> remote_error_reason == NULL ) {
4401+ cnx -> remote_error_reason = picoquic_string_create ((char * )first_byte , (size_t )reason_length );
4402+ }
4403+ }
4404+
4405+ if (bytes == NULL ) {
43984406 picoquic_connection_error (cnx , PICOQUIC_TRANSPORT_FRAME_FORMAT_ERROR ,
43994407 picoquic_frame_type_connection_close );
44004408 }
@@ -4421,7 +4429,7 @@ uint8_t * picoquic_format_application_close_frame(picoquic_cnx_t* cnx,
44214429
44224430 if ((bytes = picoquic_frames_uint8_encode (bytes , bytes_max , picoquic_frame_type_application_close )) != NULL &&
44234431 (bytes = picoquic_frames_varint_encode (bytes , bytes_max , cnx -> application_error )) != NULL &&
4424- (bytes = picoquic_frames_uint8_encode (bytes , bytes_max , 0 )) != NULL ) {
4432+ (bytes = picoquic_frames_charz_encode (bytes , bytes_max , cnx -> local_error_reason )) != NULL ) {
44254433 * is_pure_ack = 0 ;
44264434 }
44274435 else {
@@ -4433,12 +4441,19 @@ uint8_t * picoquic_format_application_close_frame(picoquic_cnx_t* cnx,
44334441
44344442const uint8_t * picoquic_decode_application_close_frame (picoquic_cnx_t * cnx , const uint8_t * bytes , const uint8_t * bytes_max )
44354443{
4436- bytes = picoquic_frames_varint_decode ( bytes + 1 , bytes_max , & cnx -> remote_application_error ) ;
4444+ uint64_t reason_length = 0 ;
44374445
4438- if (bytes == NULL ||
4439- /* TODO, maybe: skip frame type for compatibility with draft-13 */
4440- (bytes = picoquic_frames_length_data_skip (bytes , bytes_max )) == NULL )
4441- {
4446+ if ((bytes = picoquic_frames_varint_decode (bytes + 1 , bytes_max , & cnx -> remote_application_error )) != NULL &&
4447+ (bytes = picoquic_frames_varint_decode (bytes , bytes_max , & reason_length )) != NULL ){
4448+ const uint8_t * first_byte = bytes ;
4449+ if (reason_length != 0 &&
4450+ (bytes = picoquic_frames_fixed_skip (bytes , bytes_max , reason_length )) != NULL &&
4451+ cnx -> remote_error_reason == NULL ) {
4452+ cnx -> remote_error_reason = picoquic_string_create ((char * )first_byte , (size_t )reason_length );
4453+ }
4454+ }
4455+
4456+ if (bytes == NULL ) {
44424457 picoquic_connection_error (cnx , PICOQUIC_TRANSPORT_FRAME_FORMAT_ERROR ,
44434458 picoquic_frame_type_application_close );
44444459 }
0 commit comments