Skip to content

Commit ac6bbf2

Browse files
Use always the sizeof_pp2_tlv_t define instead of the hardcoded value 3
1 parent 683485c commit ac6bbf2

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/proxy_protocol.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ uint8_t *pp2_create_hdr(const pp_info_t *pp_info, uint16_t *pp2_hdr_len, int32_t
663663
{
664664
uint16_t pp2_hdr_len_padded = (*pp2_hdr_len / alignment + 1) * alignment;
665665
/* The NOOP TLV needs to be at least 3 bytes because a TLV can not be smaller than that */
666-
if (pp2_hdr_len_padded - *pp2_hdr_len < 3)
666+
if (pp2_hdr_len_padded - *pp2_hdr_len < sizeof_pp2_tlv_t)
667667
{
668668
pp2_hdr_len_padded += alignment;
669669
}
@@ -932,11 +932,11 @@ static int32_t pp2_parse_hdr(uint8_t *buffer, uint32_t buffer_length, pp_info_t
932932

933933
/* TLVs */
934934
/* Any TLV vector must be at least 3 bytes */
935-
while (tlv_vectors_len > 3)
935+
while (tlv_vectors_len > sizeof_pp2_tlv_t)
936936
{
937937
pp2_tlv_t *pp2_tlv = (pp2_tlv_t*) buffer;
938938
uint16_t pp2_tlv_len = pp2_tlv->length_hi << 8 | pp2_tlv->length_lo;
939-
uint16_t pp2_tlv_offset = 3 + pp2_tlv_len;
939+
uint16_t pp2_tlv_offset = sizeof_pp2_tlv_t + pp2_tlv_len;
940940
if (pp2_tlv_offset > tlv_vectors_len)
941941
{
942942
return -ERR_PP2_TLV_LENGTH;
@@ -1030,7 +1030,7 @@ static int32_t pp2_parse_hdr(uint8_t *buffer, uint32_t buffer_length, pp_info_t
10301030
return -ERR_PP2_TYPE_SSL;
10311031
}
10321032

1033-
pp2_sub_tlv_offset += 3 + pp2_sub_tlv_ssl_len;
1033+
pp2_sub_tlv_offset += sizeof_pp2_tlv_t + pp2_sub_tlv_ssl_len;
10341034
}
10351035
if (pp2_sub_tlv_offset > pp2_tlvs_ssl_len || (pp_info->pp2_info.pp2_ssl_info.ssl && !tlv_ssl_version_found))
10361036
{

0 commit comments

Comments
 (0)