From ce7d631064f1ab680771aa63e02653f2d79c68c2 Mon Sep 17 00:00:00 2001 From: Sukchan Lee Date: Fri, 23 Sep 2022 13:13:34 +0900 Subject: [PATCH] [GTP/PFCP] TLV length more acceptable (#1780) Acceptable even if the TLV length is smaller than expected --- lib/core/ogs-tlv-msg.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/core/ogs-tlv-msg.c b/lib/core/ogs-tlv-msg.c index ad4872ad9..3f3719d61 100644 --- a/lib/core/ogs-tlv-msg.c +++ b/lib/core/ogs-tlv-msg.c @@ -412,8 +412,7 @@ static int tlv_parse_leaf(void *msg, ogs_tlv_desc_t *desc, ogs_tlv_t *tlv) { ogs_tlv_uint8_t *v = (ogs_tlv_uint8_t *)msg; - if (tlv->length != 1) - { + if (tlv->length != 1) { ogs_error("Invalid TLV length %d. It should be 1", tlv->length); return OGS_ERROR; } @@ -427,9 +426,8 @@ static int tlv_parse_leaf(void *msg, ogs_tlv_desc_t *desc, ogs_tlv_t *tlv) { ogs_tlv_uint16_t *v = (ogs_tlv_uint16_t *)msg; - if (tlv->length != 2) - { - ogs_error("Invalid TLV length %d. It should be 2", tlv->length); + if (tlv->length < 1 || tlv->length > 2) { + ogs_error("Invalid TLV length %d.", tlv->length); return OGS_ERROR; } v->u16 = ((((uint8_t*)tlv->value)[0]<< 8)&0xff00) | @@ -443,9 +441,8 @@ static int tlv_parse_leaf(void *msg, ogs_tlv_desc_t *desc, ogs_tlv_t *tlv) { ogs_tlv_uint24_t *v = (ogs_tlv_uint24_t *)msg; - if (tlv->length != 3) - { - ogs_error("Invalid TLV length %d. It should be 3", tlv->length); + if (tlv->length < 1 || tlv->length > 3) { + ogs_error("Invalid TLV length %d.", tlv->length); return OGS_ERROR; } v->u24 = ((((uint8_t*)tlv->value)[0]<<16)&0x00ff0000) | @@ -460,9 +457,8 @@ static int tlv_parse_leaf(void *msg, ogs_tlv_desc_t *desc, ogs_tlv_t *tlv) { ogs_tlv_uint32_t *v = (ogs_tlv_uint32_t *)msg; - if (tlv->length != 4) - { - ogs_error("Invalid TLV length %d. It should be 4", tlv->length); + if (tlv->length < 1 || tlv->length > 4) { + ogs_error("Invalid TLV length %d.", tlv->length); return OGS_ERROR; } v->u32 = ((((uint8_t*)tlv->value)[0]<<24)&0xff000000) |