@@ -154,7 +154,7 @@ static const char *errors[] = {
154154
155155const char * pp_strerror (int32_t error )
156156{
157- if (error < ERR_PP1_DST_PORT || error > ERR_NULL )
157+ if (error < ERR_HEAP_ALLOC || error > ERR_NULL )
158158 {
159159 return NULL ;
160160 }
@@ -214,6 +214,27 @@ static uint8_t tlv_array_append_tlv(tlv_array_t *tlv_array, tlv_t *tlv)
214214 return 1 ;
215215}
216216
217+ static uint8_t tlv_array_append_tlv_new (tlv_array_t * tlv_array , uint8_t type , uint16_t length , const void * value )
218+ {
219+ tlv_t * tlv = tlv_new (type , length , value );
220+ if (!tlv || !tlv_array_append_tlv (tlv_array , tlv ))
221+ {
222+ return 0 ;
223+ }
224+ return 1 ;
225+ }
226+
227+ static uint8_t tlv_array_append_tlv_new_usascii (tlv_array_t * tlv_array , uint8_t type , uint16_t length , const void * value )
228+ {
229+ tlv_t * tlv = tlv_new (type , length + 1 , value );
230+ if (!tlv || !tlv_array_append_tlv (tlv_array , tlv ))
231+ {
232+ return 0 ;
233+ }
234+ tlv -> value [length ] = '\0' ;
235+ return 1 ;
236+ }
237+
217238static void tlv_array_clear (tlv_array_t * tlv_array )
218239{
219240 uint32_t i ;
@@ -653,28 +674,14 @@ static int32_t ppv2_parse(uint8_t *pkt, uint32_t pktlen, pp_info_t *pp_info)
653674
654675 switch (pp2_tlv -> type )
655676 {
656- case PP2_TYPE_ALPN :
657- {
658- tlv_t * tlv = tlv_new (pp2_tlv -> type , pp2_tlv_len , pp2_tlv -> value );
659- if (!tlv || !tlv_array_append_tlv (& pp_info -> tlv_array , tlv ))
660- {
661- return ERR_HEAP_ALLOC ;
662- }
663- break ;
664- }
665- case PP2_TYPE_AUTHORITY :
666- case PP2_TYPE_NETNS :
667- {
668- /* +1 to save it as a string */
669- tlv_t * tlv = tlv_new (pp2_tlv -> type , pp2_tlv_len + 1 , pp2_tlv -> value );
670- if (!tlv || !tlv_array_append_tlv (& pp_info -> tlv_array , tlv ))
677+ case PP2_TYPE_ALPN : /* Byte sequence */
678+ case PP2_TYPE_AUTHORITY : /* UTF8 */
679+ if (!tlv_array_append_tlv_new (& pp_info -> tlv_array , pp2_tlv -> type , pp2_tlv_len , pp2_tlv -> value ))
671680 {
672681 return ERR_HEAP_ALLOC ;
673682 }
674- tlv -> value [pp2_tlv_len ] = '\0' ;
675683 break ;
676- }
677- case PP2_TYPE_CRC32C :
684+ case PP2_TYPE_CRC32C : /* 32-bit number */
678685 {
679686 if (pp2_tlv_len != sizeof (uint32_t ))
680687 {
@@ -695,28 +702,24 @@ static int32_t ppv2_parse(uint8_t *pkt, uint32_t pktlen, pp_info_t *pp_info)
695702 return ERR_PP2_TYPE_CRC32C ;
696703 }
697704
698- tlv_t * tlv = tlv_new (pp2_tlv -> type , pp2_tlv_len , & crc32c_chksum );
699- if (!tlv || !tlv_array_append_tlv (& pp_info -> tlv_array , tlv ))
705+ if (!tlv_array_append_tlv_new (& pp_info -> tlv_array , pp2_tlv -> type , pp2_tlv_len , & crc32c_chksum ))
700706 {
701707 return ERR_HEAP_ALLOC ;
702708 }
703709 break ;
704710 }
705711 case PP2_TYPE_NOOP :
706712 break ;
707- case PP2_TYPE_UNIQUE_ID :
708- {
713+ case PP2_TYPE_UNIQUE_ID : /* Byte sequence */
709714 if (pp2_tlv_len > 128 )
710715 {
711716 return ERR_PP2_TYPE_UNIQUE_ID ;
712717 }
713- tlv_t * tlv = tlv_new (pp2_tlv -> type , pp2_tlv_len , pp2_tlv -> value );
714- if (!tlv || !tlv_array_append_tlv (& pp_info -> tlv_array , tlv ))
718+ if (!tlv_array_append_tlv_new (& pp_info -> tlv_array , pp2_tlv -> type , pp2_tlv_len , pp2_tlv -> value ))
715719 {
716720 return ERR_HEAP_ALLOC ;
717721 }
718722 break ;
719- }
720723 case PP2_TYPE_SSL :
721724 {
722725 pp2_tlv_ssl_t * pp2_tlv_ssl = (pp2_tlv_ssl_t * )pp2_tlv -> value ;
@@ -728,26 +731,32 @@ static int32_t ppv2_parse(uint8_t *pkt, uint32_t pktlen, pp_info_t *pp_info)
728731 {
729732 break ;
730733 }
734+ if (pp2_sub_tlv_offset > pp2_tlvs_ssl_len )
735+ {
736+ return ERR_PP2_TYPE_SSL ;
737+ }
731738 pp2_tlv_t * pp2_sub_tlv_ssl = (pp2_tlv_t * )((uint8_t * ) pp2_tlv_ssl -> sub_tlv + pp2_sub_tlv_offset );
732- uint16_t pp2_sub_tlv_ssl_len ;
739+ uint16_t pp2_sub_tlv_ssl_len = pp2_sub_tlv_ssl -> length_hi << 8 | pp2_sub_tlv_ssl -> length_lo ;
733740 switch (pp2_sub_tlv_ssl -> type )
734741 {
735- case PP2_SUBTYPE_SSL_VERSION :
736- case PP2_SUBTYPE_SSL_CN :
737- case PP2_SUBTYPE_SSL_CIPHER :
738- case PP2_SUBTYPE_SSL_SIG_ALG :
739- case PP2_SUBTYPE_SSL_KEY_ALG :
742+ case PP2_SUBTYPE_SSL_VERSION : /* US-ASCII */
743+ case PP2_SUBTYPE_SSL_CIPHER : /* US-ASCII */
744+ case PP2_SUBTYPE_SSL_SIG_ALG : /* US-ASCII */
745+ case PP2_SUBTYPE_SSL_KEY_ALG : /* US-ASCII */
740746 {
741- pp2_sub_tlv_ssl_len = pp2_sub_tlv_ssl -> length_hi << 8 | pp2_sub_tlv_ssl -> length_lo ;
742747 /* +1 to save it as a string */
743- tlv_t * tlv = tlv_new (pp2_sub_tlv_ssl -> type , pp2_sub_tlv_ssl_len + 1 , pp2_sub_tlv_ssl -> value );
744- if (!tlv || !tlv_array_append_tlv (& pp_info -> tlv_array , tlv ))
748+ if (!tlv_array_append_tlv_new_usascii (& pp_info -> tlv_array , pp2_sub_tlv_ssl -> type , pp2_sub_tlv_ssl_len , pp2_sub_tlv_ssl -> value ))
745749 {
746750 return ERR_HEAP_ALLOC ;
747751 }
748- tlv -> value [pp2_sub_tlv_ssl_len ] = '\0' ;
749752 break ;
750753 }
754+ case PP2_SUBTYPE_SSL_CN : /* UTF8 */
755+ if (!tlv_array_append_tlv_new (& pp_info -> tlv_array , pp2_sub_tlv_ssl -> type , pp2_sub_tlv_ssl_len , pp2_sub_tlv_ssl -> value ))
756+ {
757+ return ERR_HEAP_ALLOC ;
758+ }
759+ break ;
751760 default :
752761 return ERR_PP2_TYPE_SSL ;
753762 }
@@ -757,6 +766,12 @@ static int32_t ppv2_parse(uint8_t *pkt, uint32_t pktlen, pp_info_t *pp_info)
757766 }
758767 break ;
759768 }
769+ case PP2_TYPE_NETNS : /* US-ASCII */
770+ if (!tlv_array_append_tlv_new_usascii (& pp_info -> tlv_array , pp2_tlv -> type , pp2_tlv_len , pp2_tlv -> value ))
771+ {
772+ return ERR_HEAP_ALLOC ;
773+ }
774+ break ;
760775 case PP2_TYPE_AWS :
761776 {
762777 if (pp2_tlv_len < sizeof (pp2_tlv_aws_t ))
@@ -765,15 +780,13 @@ static int32_t ppv2_parse(uint8_t *pkt, uint32_t pktlen, pp_info_t *pp_info)
765780 }
766781 pp2_tlv_aws_t * pp2_tlv_aws = (pp2_tlv_aws_t * ) pp2_tlv -> value ;
767782 /* Connection is done through Private Link/Interface VPC endpoint */
768- if (pp2_tlv_aws -> type == PP2_SUBTYPE_AWS_VPCE_ID )
783+ if (pp2_tlv_aws -> type == PP2_SUBTYPE_AWS_VPCE_ID ) /* US-ASCII */
769784 {
770- /* +1 to save it as a string. Example: \x1vpce-08d2bf15fac5001c9 */
771- tlv_t * tlv = tlv_new (pp2_tlv -> type , pp2_tlv_len + 1 , pp2_tlv -> value );
772- if (!tlv || !tlv_array_append_tlv (& pp_info -> tlv_array , tlv ))
785+ /* Example: \x1vpce-08d2bf15fac5001c9 */
786+ if (!tlv_array_append_tlv_new_usascii (& pp_info -> tlv_array , pp2_tlv -> type , pp2_tlv_len , pp2_tlv -> value ))
773787 {
774788 return ERR_HEAP_ALLOC ;
775789 }
776- tlv -> value [pp2_tlv_len ] = '\0' ;
777790 }
778791 break ;
779792 }
@@ -785,7 +798,7 @@ static int32_t ppv2_parse(uint8_t *pkt, uint32_t pktlen, pp_info_t *pp_info)
785798 }
786799 pp2_tlv_azure_t * pp2_tlv_azure = (pp2_tlv_azure_t * ) pp2_tlv -> value ;
787800 /* Connection is done through Private Link service */
788- if (pp2_tlv_azure -> type == PP2_TYPE_AZURE )
801+ if (pp2_tlv_azure -> type == PP2_TYPE_AZURE ) /* 32-bit number */
789802 {
790803 tlv_t * tlv = tlv_new (pp2_tlv -> type , pp2_tlv_len , pp2_tlv -> value );
791804 if (!tlv || !tlv_array_append_tlv (& pp_info -> tlv_array , tlv ))
0 commit comments